views:

246

answers:

1

I'm using a XYPlot to show a line graph with 1 or more lines in it. I have it combined with a listener pattern so it can receive updates: if so, it removes the lines using a dataset.removeAllSeries() (dataset is of type XYSeriesCollection) call, and then adds the new lines using dataset.addSeries(...) However, a new graph with new lines will have different colors!

So probably the Color renderer continues to distribute new colors.

Is there a possibility to reset the renderer, so it starts out with the first color again?

+3  A: 

You can use the setSeriesPaint() method of the renderer to set a new color for each serie.

example:

renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.blue);

First parameter is the index for serie.

penguru
If I do this, Am I sure the the first NEXT color that is painted is red and the one after that is blue (even if I painted already some series on the graph?)
Roalt
How many series do you have in your plot? You can change the color of each serie before painting..
penguru
Wow, works great if you indeed first set the different colors using this setSeriesPaint on your renderer. In this way I've got rid of the cycling (random) way of getting all different colors.
Roalt