Custom Label Background in Pie Chart in Pentaho Report Designer

Hello folks!! It’s been quite a while since I wrote my last blog, and it’s always enthralling to be back to writing. Pentaho Report Designer, a tool which I love to explore, more specifically, on the charting front, as it is the least documented and most useful part of any reporting requirement.

This blog is about doing an interesting task in the PRD with pie chart. Recently, after looking at my blogs, one of my friend asked me about the possibility of a requirement in PRD, which was changing the background of labels in Pie Chart in PRD. At once, I thought it should be a configurable part, but I was not amazed on finding it missing from the configurable options. But nonetheless, I thought of doing it with Beanshell scripting (which I love the most in PRD), and got it working in just a little time. That friend of mine after getting the solution, asked me to write a blog about it as he wanted to help people with this knowledge and I’m more than happy to do so.

So here’s what you have to do in order to get the custom background of Pie chart labels in PRD. In chart properties, go to the Post Processing script section and select Beanshell from the dropdown, and write the following code in the pop up to get it working :

import java.awt.Color;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PiePlot;

PiePlot plot = (PiePlot) chart.getPlot();

One can easily customize this code to suit their need, as in changing the color to some other instead of white and much more. Below is the screenshot of what output will look like without this custom code.

Without Custom Code

Without Custom Code

With this custom code

With Custom Code

With Custom Code

Hope this helps someone and saves somebody’s valuable time. Please feel free to leave comments and requests for more such functionalities with Beanshell scripting in PRD.

Here is the sample prpt with Pentaho’s sample data.

5 thoughts on “Custom Label Background in Pie Chart in Pentaho Report Designer

  1. Hi, I have a requirement for which I cannot find a configurable option.
    My user needs to specify via a report parameter, the csv separator character.
    I know the csv separator character can be specified in the configurations in PRD, but I think only with a constant value. I need to make it parameter-dependent instead.
    Can you think of any way to do it with a script?

    • solved it. I added a BSF preprocessor script to the master report. As simple as:

      String separatorPropertyName = “org.pentaho.reporting.engine.classic.core.modules.output.table.csv.Separator”;
      String separatorPropertyValue = definition.getParameterValues().get(“p_csvSeparator”);

      definition.getReportConfiguration().setConfigProperty(separatorPropertyName ,separatorPropertyValue);

      return definition;

  2. Pingback: PDR: Change backgroud color of PieChart labels – Das JAVA-Hilfe Blog und mehr
  3. Pingback: PRD: Change backgroud color of PieChart labels – Das JAVA-Hilfe Blog und mehr

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s