This recipe demonstrates how to implement the following functionalities in Pie Charts using the same datasource:
- How to change the label font of Pie Chart:
- Create a blank report template (HowToChangeFontProperties.rml) using FruitSales.ds.
- Add a Pie Chart into the report template.
- Enter the following Java code into the “Script” tab:plot.labelFont = new java.awt.Font(“SansSerif”,0,18);
- How to change the Pie Chart transparency:
- Create a blank report template (HowToDoTransparency.rml) using FruitSales.ds.
- Add a Pie 3D Chart into the report template.
- Enter the following Java code into the “Script” tab:plot.setForegroundAlpha(0.5);
- How to include value into Label:
- Create a blank report template (HowToIncludeValueInLabel.rml) using FruitSales.ds.
- Add a Pie Chart into the report template.
- Enter the following Java code into the “Key” tab:Fruit + " - " + _2000
- How to remove Label:
- Create a blank report template (HowToRemoveLabel.rml) using FruitSales.ds.
- Add a Pie Chart into the report template.
- Enter the following Java code into the “Script” tab:plot.setLabelGenerator(null);
- How to show percentage:
- Create a blank report template (HowToShowPercentage.rml) using FruitSales.ds.
- Add a Pie Chart into the report template.
- 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); - How to show percentage with decimal format:
- Create a blank report template (HowToShowPercentageInDecimal.rml) using FruitSales.ds.
- Add a Pie Chart into the report template.
- 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)