I would like to know, if it is possible to set the both parameter as date, which in this example it take the first parameter as comparable and the second as double. But i want t
Instead of a NumberAxis
, use a DateAxis
. That will let you use a DateFormat
in the setDateFormatOverride() method.
Update: There's a complete example in org.jfree.chart.demo.TimeSeriesChartDemo1
. You might want createLineChart()
. Here's hoe you'd make the range axis show dates.
public class Example1 {
public static void main(String args[]) {
DefaultKeyedValues data = new DefaultKeyedValues();
data.addValue("8/4/2012", new Day(8, 4, 2012).getFirstMillisecond());
data.addValue("19/04/2012", new Day(19, 4, 2012).getFirstMillisecond());
CategoryDataset dataset = DatasetUtilities
.createCategoryDataset("Population", data);
JFreeChart chart = ChartFactory.createLineChart("Population", "Date",
"Population", dataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseLinesVisible(false);
DateAxis range = new DateAxis("Date");
range.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
plot.setRangeAxis(range);
ChartFrame frame = new ChartFrame("Test", chart);
frame.pack();
frame.setVisible(true);
}
}