changing order of VectorSeries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Fred
Posts: 38
Joined: Sat Dec 12, 2015 4:57 pm
antibot: No, of course not.

changing order of VectorSeries

Post by Fred » Wed Jan 04, 2017 10:21 pm

Hello,

What I want to do seems simple enough. I have a VectorRenderer that presents vectors.
Some are on top of others. The purpose would be to place a certain series that is hidden
behind other series and bring them to the top. I've rebuilt the dataset after first acquiring
the desired series inserted first (recorder 0) followed by all remaining series. However, attributes
do not appear to be inherited into the new dataset/series like visibility and series color/paint.

So for an example, I want series (id) say 10 to be pushed to the top (id=0) and bubble down
all others where current id=0 would become id=1. Again, rebuilding the dataset works but
attributes are not set when doing this.

Code: Select all


String series2Set = "test";

VectorSeriesCollection newDataSet = new VectorSeriesCollection();

VectorSeriesCollection theDataset;  // comes from retained VectorXYDataset

for (int i=0; i < theDataSet..getSeriesCount(); i++){
  VectorSeries nextSeries = theDataSet.getSeries(i);
  String nextSeriesName = theDataSet.getSeries(i).getkey().toString();
  if (nextSeriesName.equals(series2Set){
       newDataSet.addSeries(nextSeries);
       break;
  }
}
for (int i=0; i < theDataSet..getSeriesCount(); i++){
  VectorSeries nextSeries = theDataSet.getSeries(i);
  String nextSeriesName = theDataSet.getSeries(i).getkey().toString();
  if (!nextSeriesName.equals(series2Set){
       newDataSet.addSeries(nextSeries);
  }
}

...

Iterate through first removing theDataSet (series), then iterate
through the newDataSet, adding each series to theDataSet series.

In looking at the newDataSet attributes for visibility of each dataset, those that
were on in theDataSet are now off in the newDataSet. Not to mention the series color
are not the same.

Is there any easier way to just re-order which series goes to zero in the series without the
rebuilding of the dataset?

Regards,

Fred

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

Re: changing order of VectorSeries

Post by paradoxoff » Thu Jan 05, 2017 11:10 am

All of the visual information is stored in the renderer. if you change the order of series, the renderer is not notified and still uses the same color/shape/visibility defined for the first series even if the "first series" is now containing different data or is having a different name.
After you have "reorganized" the data, I suggest to create a new renderer and format that using the informations from the old renderer. If a series was moved from position 3 to position 0, you need to do the following:

Code: Select all

newRenderer.setSeriesVisible(0, oldRenderer.getSeriesVisible(3));
newRenderer.setSeriesPaint(0, oldRenderer.getSeriesPaint(3));
newRenderer.setSeriesShape(0, oldRenderer.getSeriesShape(3));
and so on.

Fred
Posts: 38
Joined: Sat Dec 12, 2015 4:57 pm
antibot: No, of course not.

Re: changing order of VectorSeries

Post by Fred » Thu Jan 05, 2017 8:55 pm

Thanks Paradoxoff - that did the trick.

Cheers and happy New year!

Fred

Locked