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();
plot.setLabelBackgroundPaint(Color.WHITE);
plot.setLabelOutlineStroke(null);
plot.setLabelShadowPaint(Color.WHITE);

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.