set plot -> DatasetCount() to 0

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
PollerJava
Posts: 81
Joined: Wed Jul 25, 2007 10:40 am

set plot -> DatasetCount() to 0

Post by PollerJava » Wed Jan 14, 2009 4:23 pm

Hi,

is it possible to set the plot- DatasetCount() to 0, because I remove all lines from the chart with the methode at the bottom but the plot.getDatasetCount()- amount remains at the amount before,
Is there any possibility to do this?

Thanks a lot,
All the best,

Code: Select all

public void removeAllLines() {
        Iterator<MyTimeSeries> it = seriesList.iterator();
        int x = 0;
        while(it.hasNext()) {                                                   // remove Dataset from the trace and the List
            MyTimeSeries ts = it.next();
            plot.setDataset(ts.getLineIndex(), null);
            plot.setRenderer(ts.getLineIndex(), null);            
            }
        seriesList.removeAll(seriesList);              
        }

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jan 14, 2009 8:51 pm

For reasons that I can't really remember, the getDatasetCount() method returns the number of slots that have been assigned for datasets, even if you reset some of them to null. I've looked at fixing this problem before - I don't remember why, but I ran into some problems so I left it as is. Maybe the quick-and-dirty solution is to add a getNonNullDatasetCount() method.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

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

Re: set plot -> DatasetCount() to 0

Post by paradoxoff » Wed Jan 14, 2009 8:55 pm

PollerJava wrote:Hi,

is it possible to set the plot- DatasetCount() to 0, because I remove all lines from the chart with the methode at the bottom but the plot.getDatasetCount()- amount remains at the amount before,
Is there any possibility to do this?

Thanks a lot,
All the best,

Code: Select all

public void removeAllLines() {
        Iterator<MyTimeSeries> it = seriesList.iterator();
        int x = 0;
        while(it.hasNext()) {                                                   // remove Dataset from the trace and the List
            MyTimeSeries ts = it.next();
            plot.setDataset(ts.getLineIndex(), null);
            plot.setRenderer(ts.getLineIndex(), null);            
            }
        seriesList.removeAll(seriesList);              
        }
The return value of plot.getDatasetCount() will never be zero. The datasets are managed in an ObjectList, and that will contain at least one entry (though the entry may be null). The same is true for the axes and renderers.
If you want to check whether the plot is "empty" (i.e. doesn´t contain any real dataset and thus couldn´t be drawn), just check for

Code: Select all

plot.getDataset() == null

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: set plot -> DatasetCount() to 0

Post by david.gilbert » Wed Jan 14, 2009 8:59 pm

paradoxoff wrote:The return value of plot.getDatasetCount() will never be zero. The datasets are managed in an ObjectList, and that will contain at least one entry (though the entry may be null). The same is true for the axes and renderers.[/code]
That is exactly right...and I think the problem with fixing the non-intuitive result returned by getDatasetCount() is that JFreeChart generally expects a 1 to 1 correspondence between datasets and renderers and so there are places in the code where getDatasetCount() is used as a proxy for getRendererCount(), and straightening out that mess is something that (a) should be done but (b) will have to wait for another day.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked