PieChart Legend color

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
nay

PieChart Legend color

Post by nay » Fri Sep 27, 2002 10:25 am

Hi !

How can I change the color legende in a PieChart ?

Thank in advance !

David Gilbert

Re: PieChart Legend color

Post by David Gilbert » Fri Sep 27, 2002 3:26 pm

You can use the setSeriesPaint(...) method inherited from the Plot class. It isn't immediately obvious, because the PiePlot doesn't really have series, but that is how it works right now...

Regards,

DG.

nay

Re: PieChart Legend color

Post by nay » Fri Sep 27, 2002 4:47 pm

ok ! thanks....I was looking in PiePlot class....

Is it possible to write around the PieChart the pourcent of each area ?

Nay

David Gilbert

Re: PieChart Legend color

Post by David Gilbert » Fri Sep 27, 2002 5:45 pm

Try some of the options in the setSectionLabelType method (in the PiePlot class).

Regards,

DG

nay

Re: PieChart Legend color

Post by nay » Mon Sep 30, 2002 10:30 am

ok...but can I use a Plot Object and a piePlot Object for the same PieChart ?
it s seem not working....
If you have an example, it s welcome !

my code is :
....
Plot plot = chart.getPlot();
plot.setSeriesPaint(mylegendColor);

PiePlot piePlot = new PiePlot(mypieData);
piePlot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
....

Thanks


ps : I buy the doc but there is no Part about Customising PiePlot :(...

David Gilbert

Re: PieChart Legend color

Post by David Gilbert » Mon Sep 30, 2002 1:09 pm

The setSeriesPaint(...) method is defined in the Plot class, but it is also inherited by the PiePlot class. So you can do this:

PiePlot piePlot = new PiePlot(mypieData);
piePlot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
piePlot.setSeriesPaint(myLegendColors);

Regards,

DG

nay

Re: PieChart Legend color

Post by nay » Mon Sep 30, 2002 1:34 pm

Yes I tried this but it s do nothing....

Perhaps I need to do a PlotChangeEvent or something like this after ?

Do I need to invoke the piePlot.draw() method, normaly it s invoke with ChartFactory.createPieChart("title",mypieData, true) ?

David Gilbert

Re: PieChart Legend color

Post by David Gilbert » Mon Sep 30, 2002 1:45 pm

OK, if you are using the ChartFactory to create your pie chart, then the PiePlot has been created for you. So, to get a reference to it, you need to do this:

PiePlot myPlot = (PiePlot) myChart.getPlot();

Then you can do the other stuff:

myPlot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
myPlot.setSeriesPaint(myLegendColors);

If you just create a new PiePlot instance, then it has no connection at all with the chart you created previously.

Regards,

DG.

nay

Re: PieChart Legend color

Post by nay » Mon Sep 30, 2002 2:17 pm

it s ok !
Thank for your help !
Nay

Locked