4

I am creating pie charts using JFreeChart, and I want to set the value and the label seperately like in iReport. In other words, I want the chart to show different results on the pie than in the legend. Is there any way that I can achieve this?

wattostudios
  • 8,666
  • 13
  • 43
  • 57
Halo
  • 1,524
  • 3
  • 24
  • 39

1 Answers1

10

The MessageFormat ArgumentIndex values correspond to the series name, domain and range. You can set a different generator for each series or for all series in the base.

PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} {2}"));

Addendum: For PiePlot, the values have a slightly different meaning—series name, value and percentage—as shown here.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • but I don't think I should use BarRenderer, I'm creating a pie chart – Halo Aug 24 '10 at 06:35
  • @Halo: Oops! Thanks for catching this. Right principle, wrong `Plot` subclass. Revised above, _and_ I learned something new. :-) – trashgod Aug 24 '10 at 14:51