This recipe shows how to add percentage into pie charts and how to remove individual legend for multiple pie chart by using Java coding.
Major steps include the following:
- How to add percentage into pie charts using Java coding
- Create a blank report template (HowToAddPercentage.rml) using the datasource (FruitSales.ds).
- Add a Multiple Pie Chart into the blank area under “Section Header”.
- Enter the following Java coding into the “Script” tab page:importClass(Packages.org.jfree.chart.labels.StandardPieSectionLabelGenerator);
var chart = plot.getPieChart();
var p = chart.plot;
p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); - How to remove individual legend for multiple pie chart by using Java coding
- Create a blank report template (HowToRemoveIndividualLegend.rml) using the datasource (FruitSales.ds).
- Add a Multiple Pie Chart into the blank area under “Section Header”.
- Enter the following Java coding into the “Script” tab page:var chart = plot.getPieChart();
chart.removeLegend();
Screenshot for adding percentage:
Screenshot for removing individual legend:
To download the necessary files for this recipe, refer to the attached ZIP package.
MultiplePieChart.zip (5.4 KB)