XYPlot.getDatasetCount() returns wrong number

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
LukasW
Posts: 9
Joined: Thu Nov 02, 2006 8:10 pm

XYPlot.getDatasetCount() returns wrong number

Post by LukasW » Wed Aug 13, 2008 11:30 am

Hi,

I found two problems with this method:

1) it returns 1 when there are no datasets in the plot

2) if I add datasets to a plot and then remove them with plot.setDataset(i, null) they still count!

Will this be fixed anytime soon or is there a workaround? I'm using jfreechart-1.0.10.

Thanx
/Lukas

TeAmigo
Posts: 1
Joined: Wed Feb 23, 2011 11:18 pm
antibot: No, of course not.

Re: XYPlot.getDatasetCount() returns wrong number

Post by TeAmigo » Wed Feb 23, 2011 11:44 pm

If you go into source for XYPlot, the 0 arg constructor calls the 4-arg constructor with null for the dataset. In that constructor, on about line 567, you see this:

Code: Select all

      this.datasets.set(0, dataset);
      if (dataset != null) {
          dataset.addChangeListener(this);
      }
If you move the set call under the test, that fixes the problem of getDatasetCount() returning 1 when it should be 0.

Code: Select all

      
      if (dataset != null) {
          this.datasets.set(0, dataset);
          dataset.addChangeListener(this);
      }

Locked