Hi
After creating a chart, I dynamically add new time series to it, and I
want to use the data by looking at the dataset. It's ok when I add the
first series. But when I add the second series it fails.
Section of the offending code: -
for (int row=0; row < total_rows; row++) {
XYPlot plot = (XYPlot)chart.getChart().getPlot();
XYDataset dataset = plot.getDataset(row);
...
...
}
Run it in the debugger, I find the datasets.size remains 1, even though
datasets.objects[0].data.elementData contains 2 time series.
This results in plot.getDataset(1) to return null
because it uses if (this.datasets.size() > index) to
check whether the index is valid.
Have some experienced this problem before?
Thanks.
Phil
XYPlot.datasets.size field doesn't update ?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I'd guess that you have one dataset with two series in it. If not, could you post a JUnit test that shows the failure, and tell me the version of JFreeChart you are using.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Thanks David. You're right.
I created a TimeSeriesCollection object and added 2 time series to
it, and then added the TimeSeriesCollection object
to createTimeSeriesChart(). So there is really 1 dataset.
If I have N time series, which way is more efficient for jfreechart: -
(1) Create a TimeSeriesCollection, then add the N time series to it.
And then pass the TSC to: -
ChartFactory.createTimeSeriesChart
(CHART_TITLE, "Time", "Value", TSC, true, false, false)
(2) Create N dataset each has 1 time series then add these N
datasets to a Plot inside a loop like: -
chart.getXYPlot().setDataset(datasets)
Thanks for your help.
Regards,
Phil
I created a TimeSeriesCollection object and added 2 time series to
it, and then added the TimeSeriesCollection object
to createTimeSeriesChart(). So there is really 1 dataset.
If I have N time series, which way is more efficient for jfreechart: -
(1) Create a TimeSeriesCollection, then add the N time series to it.
And then pass the TSC to: -
ChartFactory.createTimeSeriesChart
(CHART_TITLE, "Time", "Value", TSC, true, false, false)
(2) Create N dataset each has 1 time series then add these N
datasets to a Plot inside a loop like: -
chart.getXYPlot().setDataset(datasets)
Thanks for your help.
Regards,
Phil