Skip to content

Proper way to iterate over datasets in XYPlot? #201

@lynnskii

Description

@lynnskii

I have noticed that datasets are stored in a map by index in XYPlot. However, there is no exposed way of iterating over the datasets other than getDataset(int index). The rub is that getDatasetCount() returns the number of datasets in the map, not the maximum index value.

I have plots that have optional datasets, so there may be gaps in the indices. For instance: datasets={0=BaseDataset, 2=Dataset2}. There is no dataset with index=1. When you try to iterate over the available datasets in a generic way, there's no way to know what dataset indices are actually available for the plot:

for (int i=0; i<plot.getDatasetCount(); i++) { // plot.getDatasetCount() = 2
XYDataset d = plot.getDataset(i); // i will be 0 and 1, so you never get dataset 2.
}

To properly obtain all a plot's datasets when you don't know what the indices may be, should getDatasetCount() return the maximum value of the datasets map's keySet()? Or other methods provided to return, say, an unmodifiable collection of the datasets map's values()? Internally to XYPlot, this is how iteration is done: for (XYDataset dataset: this.datasets.values()) { ... }

The same issue applies to the other maps by index in XYPlot: getRendererCount(), getDomainAxisCount(), getRangeAxisCount()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions