How to keep series' rendering props after remove?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
d_koenig
Posts: 3
Joined: Sat Jan 17, 2009 8:01 pm

How to keep series' rendering props after remove?

Post by d_koenig » Mon May 11, 2009 8:16 pm

Hi,

Is it possible to keep a series' automatically given rendering properties (like color, shape, etc) after removing another series from chart?

Maybe there is a boolean flag somewhere, that I did not find yet....
like setKeepEverythingLikeItWas(damnidTrue) ? :mrgreen:

Thanks for help! :)

MitchBuell
Posts: 47
Joined: Thu Dec 11, 2008 7:59 pm

Re: How to keep series' rendering props after remove?

Post by MitchBuell » Mon May 11, 2009 9:02 pm

By default the Plot uses a DrawingSupplier to internally automatically generate some default Series colors, shapes, etc. Each time you add a Series to the Plot, the Plot basically does a DrawingSupplier.getNextColor() and .getNextShape(). If you then remove the Series and add it back, you're going to get the next color and shape. You can turn this off and manually set each Series colors and shapes. Or you can play with the DrawingSupplier.

d_koenig
Posts: 3
Joined: Sat Jan 17, 2009 8:01 pm

Re: How to keep series' rendering props after remove?

Post by d_koenig » Mon May 11, 2009 10:51 pm

MitchBuell wrote:You can turn this off and manually set each Series colors and shapes. Or you can play with the DrawingSupplier.
Thank you for your response.
What do you mean with turn off? To set null for plot's DrawingSupplier?

MitchBuell
Posts: 47
Joined: Thu Dec 11, 2008 7:59 pm

Re: How to keep series' rendering props after remove?

Post by MitchBuell » Tue May 12, 2009 1:55 pm

The AbstractRenderer class, which ALL of the renderers extends, offers a bunch of setAutoPopulateSeriesXXX(boolean) methods to turn on or off the automatic generation of colors/shapes/etc. If you set all of these to false, then your chart will have a whole bunch of exactly similar looking lines. Then you can manually set specific series colors/shapes/etc.

Check out AbstractRenderer in the Javadoc.

Code: Select all

((AbstractRenderer)chart.getXYPlot().getRenderer()).setAutoPopulateSeriesPaint(false);
((AbstractRenderer)chart.getXYPlot().getRenderer()).setAutoPopulateSeriesShape(false);
etc.

meara
Posts: 1
Joined: Sun May 17, 2009 8:14 pm

Re: How to keep series' rendering props after remove?

Post by meara » Sun May 17, 2009 8:24 pm

I have a similar problem. I allow users to turn each data series on and off with a checkbox. By default (even when I set the colors manually on the renderer), removing one series changes the colors of every other series that comes after it. This is because the API maps paint color to the index of the series instead of the actual XYSeries object. I would love it if instead of calling setSeriesPaint(0, Color.red), I could call setSeriesPaint(mySeries, Color.red).

Right now, my only real workaround is to maintain my own map and reset all the colors (by index) every time a series is added or removed.

Any suggestions welcome!

Locked