JFreeChart is a free and pure java chart library for
creating professional quality charts.
This requires the libraries
jfreechart-1.0.13.jar and
jcommon-1.0.8.jar
to be in classpath.
The following example shows creating a simple Time series chart.
// Prepare the data set
TimeSeries population = new TimeSeries("Indian Population");
population.add(new Day(1, 3, 1961), 439234771);
population.add(new Day(1, 3, 1971), 548159652);
population.add(new Day(1, 3, 1981), 683329097);
population.add(new Day(1, 3, 1991), 843387888);
population.add(new Day(1, 3, 2001), 1028610328);
population.add(new Day(1, 3, 2011), 1210193422);
TimeSeriesCollection dataset = new TimeSeriesCollection(population);
// Create the chart
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Population of India", "Date", "Population", dataset,
true, true, false);
//Get the plot and set date format
XYPlot plot = chart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
// Render the frame
ChartFrame chartFrame = new ChartFrame("Simple TimeSeries Chart", chart);
chartFrame.setVisible(true);
chartFrame.setSize(600, 300);
}
}