Roalt Roalt - 3 years ago 165
Java Question

How to reset the rendered colors used in JFreeChart

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download