Did getDataset change between version 1.0.11 and 1.0.19?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
a344254
Posts: 21
Joined: Wed Oct 01, 2008 9:18 pm

Did getDataset change between version 1.0.11 and 1.0.19?

Post by a344254 » Wed May 03, 2017 2:26 pm

I have a program that has always iterated through a chart that has multiple datasets - one at ID 0 and one at ID 10 by doing

Code: Select all

for (int datasets=0; datasets<plot.getDatasetCount(); datasets++)
        {   try{    CategoryDataset dset = plot.getDataset(datasets);
                    ...
            }
            catch(Exception e)
            { System.out.println(e.toString());}
        }
where plot.getDatasetCount() would return 2, and the first call to plot.getDataset(which would use 0) would return the one at ID 0, and the second call to plot.getDataset(which would use 1) would return the one at ID 10.

Since upgrading to 1.0.19, my first call to getDataset returns the one at ID 0, but the second call is returning NULL because there is no dataset with and ID of "1". If I specify plot.getDataset(10) then I get the expected dataset, but that's not the functionality that I'm used to.

Did something change or am I doing something wrong?

Thanks,
Kevin

a344254
Posts: 21
Joined: Wed Oct 01, 2008 9:18 pm

Re: Did getDataset change between version 1.0.11 and 1.0.19?

Post by a344254 » Wed May 03, 2017 2:32 pm

Actually I'm mistaken - I just reverted back to 1.0.11 and see that when I call plot.getDatasetCount() I actually receive a "10", where in 1.0.19 I receive a "2". So in 1.0.11 I would end up iterating through the datasets until I got up to "10" and get a valid dataset, where now I only iterate up to 2 and never reach that dataset. Is this a bug or is there a change in the way you're supposed to iterate through a chart's datasets?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Did getDataset change between version 1.0.11 and 1.0.19?

Post by paradoxoff » Wed May 03, 2017 5:05 pm

Check this thread. Does is explain the change in behaviour that you are seeing?

a344254
Posts: 21
Joined: Wed Oct 01, 2008 9:18 pm

Re: Did getDataset change between version 1.0.11 and 1.0.19?

Post by a344254 » Wed May 03, 2017 5:38 pm

Yes it does sound the same. Is that how I need to iterate the datasets now - getDatasetIndexes?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Did getDataset change between version 1.0.11 and 1.0.19?

Post by paradoxoff » Thu May 04, 2017 8:45 pm

I guess so.
I have commented on this approach in the linked thread.
Personally, I definitely prefer the old-fashioned way:
- an XYPLot has a list of dataset, renderers, axes, and so on.
- mapping between datasets and renderers is based on the indices in the lists: the nth dataset is rendered by the nth renderer.
- mapping between dataset and axes is created using the mapDatasetToXYZAxes methods.
I just had a look at how the iteration over the datasets is achieved, and I find it unneccesary complex compared to a simple iteration over a list. But since the list to map replacement has apparently been integrated into so many different places, we will probably have to live with that.

a344254
Posts: 21
Joined: Wed Oct 01, 2008 9:18 pm

Re: Did getDataset change between version 1.0.11 and 1.0.19?

Post by a344254 » Fri May 05, 2017 1:25 pm

I implemented the same fix that was mentioned in the thread and rebuilt from the source which works and let's me iterate over the datasets, but this will be painful to have to do anytime a new revision of JFreeCharts is released. Hopefully the iteration will either go back to the old way, or include the getDatasetIndexes method in the new release. Thanks for your help.

Locked