I'm a french student, and I develop an application using JFreeChart.
I have to make a chart with plots and lines, how I can do that ?
Sorry for my english

Regards,
Gaël
Code: Select all
// Create a single plot containing both the scatter and line
XYPlot plot = new XYPlot();
/* SETUP SCATTER */
// Create the scatter data, renderer, and axis
XYDataset collection1 = getScatterPlotData();
XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); // Shapes only
ValueAxis domain1 = new NumberAxis("Domain1");
ValueAxis range1 = new NumberAxis("Range1");
// Set the scatter data, renderer, and axis into plot
plot.setDataset(0, collection1);
plot.setRenderer(0, renderer1);
plot.setDomainAxis(0, domain1);
plot.setRangeAxis(0, range1);
// Map the scatter to the first Domain and first Range
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
/* SETUP LINE */
// Create the line data, renderer, and axis
XYDataset collection2 = getLinePlotData();
XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); // Lines only
ValueAxis domain2 = new NumberAxis("Domain2");
ValueAxis range2 = new NumberAxis("Range2");
// Set the line data, renderer, and axis into plot
plot.setDataset(1, collection2);
plot.setRenderer(1, renderer2);
plot.setDomainAxis(1, domain2);
plot.setRangeAxis(1, range2);
// Map the line to the second Domain and second Range
plot.mapDatasetToDomainAxis(1, 1);
plot.mapDatasetToRangeAxis(1, 1);
// Create the chart with the plot and a legend
JFreeChart chart = new JFreeChart("Multi Dataset Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
Code: Select all
// Map the line to the FIRST Domain and second Range
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
Code: Select all
renderer.setBasePaint(Color.blue);
renderer.setBaseFillPaint(Color.blue);