Two or more XYDatasets in ScatterPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
droop
Posts: 7
Joined: Fri Feb 01, 2008 11:01 am

Two or more XYDatasets in ScatterPlot

Post by droop » Sun Mar 09, 2008 12:50 am

I want to have two or more sets of data in my ScatterPlot. How should I do, is it possible? The following code I use at the moment, because the ScatterPlot require the type XYDataset, but it is only one set of data. I can not find data.add() or something like this.... please help me


/Mike


XYDataset data = createDataset();


JFreeChart chart = ChartFactory.createScatterPlot(
"Scatter-plot diagram", // chart title
"X", // x axis label
"Y", // y axis label
data, // <------------------------data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
Writing examination thesis,Master, in computer science.

stledger
Posts: 14
Joined: Sun Mar 09, 2008 7:39 am

Re: Two or more XYDatasets in ScatterPlot

Post by stledger » Thu Mar 13, 2008 4:55 am

droop wrote:I want to have two or more sets of data in my ScatterPlot. How should I do, is it possible? The following code I use at the moment, because the ScatterPlot require the type XYDataset, but it is only one set of data. I can not find data.add() or something like this.... please help me


/Mike


XYDataset data = createDataset();


JFreeChart chart = ChartFactory.createScatterPlot(
"Scatter-plot diagram", // chart title
"X", // x axis label
"Y", // y axis label
data, // <------------------------data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
I'm new to JFreeChart myself, but you can add and remove data series from an XYSeriesCollection, like this:

XYSeriesCollection dataSet = new XYSeriesCollection();
dataSet.addSeries(line1);
dataSet.addSeries(line2); ... etc. where the line1 and line2 are XYSeries. Depending upon the type of data you're displaying XYSeriesCollection may not be the right choice, but when you figure out the correct class, it will have an add mehtod.

Was this what you were asking for?

John

Locked