[Chart] Pie Chart

This recipe demonstrates how to implement the following functionalities in Pie Charts using the same datasource:

  1. How to change the label font of Pie Chart:
  2. Create a blank report template (HowToChangeFontProperties.rml) using FruitSales.ds.
  3. Add a Pie Chart into the report template.
  4. Enter the following Java code into the “Script” tab:plot.labelFont = new java.awt.Font(“SansSerif”,0,18);
  5. How to change the Pie Chart transparency:
  6. Create a blank report template (HowToDoTransparency.rml) using FruitSales.ds.
  7. Add a Pie 3D Chart into the report template.
  8. Enter the following Java code into the “Script” tab:plot.setForegroundAlpha(0.5);
  9. How to include value into Label:
  10. Create a blank report template (HowToIncludeValueInLabel.rml) using FruitSales.ds.
  11. Add a Pie Chart into the report template.
  12. Enter the following Java code into the “Key” tab:Fruit + " - " + _2000
  13. How to remove Label:
  14. Create a blank report template (HowToRemoveLabel.rml) using FruitSales.ds.
  15. Add a Pie Chart into the report template.
  16. Enter the following Java code into the “Script” tab:plot.setLabelGenerator(null);
  17. How to show percentage:
  18. Create a blank report template (HowToShowPercentage.rml) using FruitSales.ds.
  19. Add a Pie Chart into the report template.
  20. Enter the following Java code into the “Script” tab:importClass(Packages.org.jfree.chart.labels.StandardPieSectionLabelGenerator);
    var gen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
    plot.setLabelGenerator(gen);
  21. How to show percentage with decimal format:
  22. Create a blank report template (HowToShowPercentageInDecimal.rml) using FruitSales.ds.
  23. Add a Pie Chart into the report template.
  24. Enter the following Java code into the “Script” tab:importClass(java.text.DecimalFormat);
    importClass(Packages.org.jfree.chart.labels.StandardPieSectionLabelGenerator);
    var gen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})", new
    DecimalFormat(“0.00”), new DecimalFormat(“0.00%”));
    plot.setLabelGenerator(gen);

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