Pie chart Legend format change

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
piyush
Posts: 4
Joined: Sat Jul 02, 2005 6:35 pm

Pie chart Legend format change

Post by piyush » Sun May 07, 2006 2:42 pm

Hi all,
I have a customization to be done in the legends being generated (below the chart) for the Pie charts. I want only the name of the category to be displayed and not the name = value pattern as it currently exists.
If I try new StandardPieSectionLabelGenerator("{1}), it only changes for the labels being displayed next to the pie sections.
Please help me.
Thanks in advance.

Regards,
Piyush

piyush
Posts: 4
Joined: Sat Jul 02, 2005 6:35 pm

Post by piyush » Sun May 07, 2006 4:30 pm

Hi All,
I found out how to do that. It can be done using

Code: Select all

pieplot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
.

Now I'm facing another problem. If the legend name of any section is too long, then I want to crop it off after some size. Say if my legend name is No of Users in Category X, then I would like to display only the first 10 characters of the above label, followed by trailing spaces. How do I go about it.

Any suggestion / help is highly appreciated.

Thanks in advance,

Regards,
Piyush

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue May 09, 2006 10:18 am

For that, you'll need to create your own PieSectionLabelGenerator class (you could start with StandardPieSectionLabelGenerator and modify it as necessary).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

tatia34
Posts: 23
Joined: Fri Apr 27, 2007 2:11 pm
Location: France

Post by tatia34 » Wed May 23, 2007 4:12 pm

Hi,

I try to modify the legend to decrease the lenght of legend labels...
On CategoryPlot or XYPlot on, we can do a setFixedLegendItems(..) to change legends items... But for PiePlot, method doesn't exist... is-there a solution or I do rewrite a custom PiePlot ?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu May 24, 2007 10:08 am

I guess the fixedLegendItems attribute could be moved up into the Plot class...anyone else have any thoughts about that?

What do you display in the legend for the PiePlot? Generally, I hide the legend in this case, because you can easily label the pie sections right on the plot and so the legend is redundant.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

tatia34
Posts: 23
Joined: Fri Apr 27, 2007 2:11 pm
Location: France

Post by tatia34 » Thu May 24, 2007 3:26 pm

It's rigth that I label the pie sections and that the legend is redundant....
I will have a discuss with my training course chief to know if I can not display the legend...

thank you for the response

Locked