I'm new to JFreeChart but I'm trying to wrap my brain arround the concept.
I have created a StackedXYAreaChart with a TimeTableXYDataset and reading values from an Oracle database. What bugs me is when I start the app, there are no domain axis labels (hh:mm). They show up when the graph starts to fill upp and is complete when it is time to remove the first item in the series.
Is there a way to pre initialize the domain axis so it shows a time span +/- x hours from current time. I tried setMinimumDate and setMaximum date and it looked nice at first, but the domain axis started to move 'the wrong way'.
Code: Select all
private JFreeChart createAreaChart(final TimeTableXYDataset dataset) {
final JFreeChart chart = ChartFactory.createStackedXYAreaChart(
"Stacked test chart",
"Time",
"Value",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
final StackedXYAreaRenderer render = new StackedXYAreaRenderer();
render.setSeriesPaint(0, Color.RED);
render.setSeriesPaint(1, Color.GREEN);
DateAxis domainAxis = new DateAxis();
domainAxis.setAutoRange(true);
domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 60));
// domainAxis.setMinimumDate(new Date(System.currentTimeMillis() - 3600 * 1000));
// domainAxis.setMaximumDate(new Date(System.currentTimeMillis() + 3600 * 1000));
XYPlot plot = (XYPlot) chart.getPlot();
plot.setRenderer(render);
plot.setDomainAxis(domainAxis);
plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
plot.setForegroundAlpha(0.5f);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setNumberFormatOverride(new DecimalFormat("#,###.#"));
rangeAxis.setAutoRange(true);
return chart;
}