[Chart] Multiple Pie Chart

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:

  1. How to add percentage into pie charts using Java coding
  2. Create a blank report template (HowToAddPercentage.rml) using the datasource (FruitSales.ds).
  3. Add a Multiple Pie Chart into the blank area under “Section Header”.
  4. 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})"));
  5. How to remove individual legend for multiple pie chart by using Java coding
  6. Create a blank report template (HowToRemoveIndividualLegend.rml) using the datasource (FruitSales.ds).
  7. Add a Multiple Pie Chart into the blank area under “Section Header”.
  8. Enter the following Java coding into the “Script” tab page:var chart = plot.getPieChart();
    chart.removeLegend();

Screenshot for adding percentage:

MultiplePieChart-Percentage

Screenshot for removing individual legend:

MultiplePieChart-RemoveLegend

To download the necessary files for this recipe, refer to the attached ZIP package.
MultiplePieChart.zip (5.4 KB)