0
votes

I am pretty done with my chart. But the one thing is still tricky.

How can I define the colors for each series. I have 3 series datasets (RED, GREEN, BLUE) and have also a checkbox on my chart. The checkboxes are designed as when I tick one of them, one dataset is getting invisible and vice versa it is getting visible again.

I defined my colors as follows initially.

            XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        renderer.setSeriesPaint(0, Color.red);
        renderer.setSeriesPaint(1, Color.green);
        renderer.setSeriesPaint(2, Color.blue);

This is pretty much working in first instance. However when I untick all three check buttons and then start ticking from the end (BLUE), the chart is drawing the BLUE line correctly from coordinate perspective but the color is RED. The same problem occurs when I re-tick GREEN and RED. It always start with colors RED, GREEN and BLUE. But I want to draw the lines respectively on its defined color.

Any ideas??

1

1 Answers

1
votes

You have set series 0 to red:

renderer.setSeriesPaint(0, Color.red);

If your code is removing the series and re-adding it when the checkbox is unchecked/checked then the first series added will be series 0.

Set the colour when you add the series not when you create the chart as series 0 is not always red