set color for secondary axis TimeSeries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
bztom33
Posts: 35
Joined: Tue Jul 11, 2006 10:35 pm

set color for secondary axis TimeSeries

Post by bztom33 » Fri Aug 22, 2008 4:32 am

Hi,

I was able to change the color for the first set of timeseries xyplot.
I tried to change the color for the secondary axis xyplot. It does not work.
Is it there's way to do it?

Code: Select all

 renderer1.setSeriesPaint(0, Color.blue); --working        primary axis (left)
 renderer1.setSeriesPaint(1, Color.green); --not working secondary axis (right).

kbng11
Posts: 11
Joined: Wed Aug 20, 2008 8:49 am
Location: Kuala Lumpur, Malaysia

Post by kbng11 » Fri Aug 22, 2008 6:58 am

If you meant a graph with 2 bars or 2 lines. I tested and it worked fine for me :wink:
Strafing for excellence

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

Post by paradoxoff » Fri Aug 22, 2008 8:05 am

Hi bztom33,
I had some problems to find out myself how the axes, datasets and renderers collaborate!
Since you have a second axis, it is clear that you assigned (at least) a second dataset to your plot and mapped that to the "secondary axis".
If you have n datasets that you want to format independently, you have to assign n renderer to the plot! The integer index in the setXXX() methods of the renderer does not refer to all series of the plot, but only to the series of the dataset that has the same index as the renderer.
With your code

Code: Select all

renderer1.setSeriesPaint(1, Color.green); --not working secondary axis (right).
you are setting the color of the second series of that dataset that has the same index than the renderer1. But what you apparently want is to set the color of the first (and maybe only) series of the second dataset. Here is how this can be achieved

Code: Select all

plot.setDataset(1,yourDatasetAssignedToSecondaryAxis);
plot.setRenderer(1,aNewRenderer);
aNewRenderer.setSeriesPaint(0,Color.GREEN);

bztom33
Posts: 35
Joined: Tue Jul 11, 2006 10:35 pm

Post by bztom33 » Fri Aug 22, 2008 9:06 am

Thanks for your help I got it working.

Code: Select all

old code:
subplot1.setRenderer(1, new StandardXYItemRenderer());

new code:
         final XYItemRenderer renderer1a = new StandXYItemRenderer();
         subplot1.setRenderer(1,renderer1a);
         renderer1a.setSeriesPaint(0,Color.GREEN); ==secondary axis series1
         renderer1a.setSeriesPaint(1,Color.GREEN); ==secondary axis series2 

Locked