Search code examples
jasper-reportsjfreechartireport

iReport 5.0.0 - How to display percentage inside each pieslice


I'm trying to create a pie chart in iReport 5 where the percentage of each slice of the pie is displayed inside the pie chart. The closest I have come to this is to show the percentage outside the pie chart. I have also tried to use a customizer class. What would I need to add to make the pie chart display some text or the percentages inside each pie slice as the below picture shows?

a busy cat
(source: jfree.org)


Solution

  • Found a way to do this by adding this to the Customizer class:

    Plot plot = chart.getPlot();
    PiePlot piePlot = (PiePlot)plot;
    piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
    piePlot.setSimpleLabels(Boolean.TRUE);
    

    I consider this the solution for the problem.