X-Axis Label Wrap in Pentaho Report Designer

I am back with yet again an interesting possibility in Pentaho Report Designer using Beanshell Script. As I said in my earlier post that Beanshell Script is a blessing in PRD, this post will strengthen the belief of many in this fact. So let’s have a look at the new possibility.

I was working with PRD in previous month, when I was needed to do an interesting stuff in PRD which is to wrap X-axis label for bar chart in Pentaho Report Designer. PRD does not have any configuration for this. I searched about this possibility through many of the forums and blogs but all in vain. Meanwhile, I came across a link (http://jira.pentaho.com/browse/PRD-3247) of official pentaho jira request regarding the same which was opened nearly 34 months back and is still open.

I was amazed looking at this so old Jira request open. I thought that it might be possible using the Beanshell scrtip. I hardly spent my 30 minutes to get this job done using Beanshell script and walah!! I got the desired output.For those who don’t know about Beanshell script, here is the link to my previous blog Custom Value Axis Scale in Pentaho Report Desinger, where you will get a short brief about Beanshell Script and where to write Beanshell Script in PRD.

Currently PRD does not wrap a big label on X-Axis of a chart. Whenever a label is bigger it just dotify it and displays it like “labelnotw….”. But sometimes in practical implementations, the label may be as big as 30 characters and the client does not want it to be dotify. Below are the two sample images, of what is the current problem and what is to be the expected output, for a better clarification on the usability of this blog.

Current Result:


Labels Without Wrapping

Desired Result:


Labels After Wrapping

PRD don’t have any by default feature to achieve this but having said that PRD has a feature using which you can achieve this and that is Chart-Post Processing Scripting. Beanshell is also one of the chart post processing script available in PRD.

To get the above output you need to write the following few lines of code in PRD’s chart post processing script having beanshell as the type.

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.axis.CategoryAxis;

CategoryPlot myPlot = chart.getCategoryPlot();
CategoryAxis myAxis = myPlot.getDomainAxis();

And here you go. It seems to be a very simple thing when you see the output but believe me when you search through the internet you will not get any of the satisfactory solution to achieve this. But it is a very useful feature and is often demanded by the customers.

Here is the sample report to download http://tinyurl.com/X-AxisLabelWrap

Hope this post helps someone and feel free to give comments and suggestion. I’ll be writing more and more to help and share the bit of my knowledge with people on global platform.

Custom Value Axis Scale in Pentaho Report Designer

The Pentaho Report Designer (PRD) has evolved as a very feature-rich product over the last few years. But still there are some features, that are not documented anywhere. You come to know these features as you dig more and more into the tool.

In this blog, I want to share one of those many unsung possibilities in PRD. While working with charts in PRD, sometimes it is required to have a custom range on the value axis(Y Axis). This seems to be a very common need to customize the scale as required but, PRD does not have any default option for this functionality, but still there is a out of the box work around which can make this happen and i.e. Beanshell Script.

For those who are new to Beanshell Script, Beanshell Script is like a blessing in PRD, especially when you are working with charts. It is one of the Chart-Post Processing Script that you can write in PRD. To write a Beanshell Script in PRD just select the type of Chart-Post Processing script as “beanshell” from the available values and write the script in the next field. Refer to the image for more clarity on where to write the beanshell script.

Pentaho Report Designer

Pentaho Report Designer

You can write the script in the new window which pops up. There are two ways you can customize the value axis range using beanshell script:

1)      Setting the fixed upper and lower bound for the range

2)      Taking the upper bound and lower bound from the minimum and maximum values of the chart

Fixed Upper and Lower Bound:
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;

CategoryPlot chartPlot = chart.getCategoryPlot();
ValueAxis yAxis= chartPlot.getRangeAxis();

Where “maxValue” and “minValue” can be any values that you want to set as upper and lower bound respectively.

Setting Bounds Based on the Values of Chart:
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.axis.ValueAxis;
import java.util.*;
import java.math.*;
import java.util.List;
import java.util.ArrayList;

CategoryPlot chartPlot = chart.getCategoryPlot();
ValueAxis yAxis= chartPlot.getRangeAxis();
data = chartPlot.getDataset();
keys = data.getRowKeys();
ArrayList dataVals = new ArrayList();
for (int i=0;i<keys.size();i++)
Double maxVale=(Collections.max(dataVals)).doubleValue();
Double minVale=(Collections.min(dataVals)).doubleValue();

And here you go. This is how you can achieve this.Here is the sample output.

Custom Value Axis Scale

Custom Value Axis Scale

And here is the link to download the sample prpt for this.

Trust me,  it is one of the many possibilities using Beanshell Script.Hope this post helps people and soon will be coming with many more possibilities in PRD.

Horizontal Gradient Bar chart in Pentaho Reporting Designer

As a hard core UI / UX designer, I always feel color plays a very important role in our life. Without colors anything will be colorless and same I feel when I see any BI dashboards and reports without any color.

I never understand why people want to create a report in Gray scale or in single color only. Reports should have some colors in that, where people can see the details and highlight those points where they need to focus more.

On one of my recent project, I have seen a very beautiful report which was created in PowerPoint and same I need to replicate in Pentaho Report Designer. The report was pretty cool and was having so many details and challenges.

Apart from other challenges like Multiple Language, Dynamic Formatting and complex formulas, I was having big time challenge with Gradient Horizontal Bar Charts. I have never seen gradient color in horizontal bar charts under Pentaho Report Designer, so was little surprised.

But finally understood the way to handle this challenge and now showcasing the same.

For creating a gradient horizontal bar chart in Pentaho report designer I used a beanshell code which works with JFree Charting library.

There is couple of other Post-Processing script also available in Pentaho Report Designer which processes after the chart renders. I created this with beanshell because JFree has good support with beanshell rather than other Post-Processing script.

You can add the beanshell script on your chart in report designer, by double clicking on your chart and selecting beanshell under Scripting > Chart Post-Processing Script in left panel.

Pentaho Report Designer

Pentaho Report Designer

Then write the following beanshell script for gradient horizontal bar chart

import java.util.*;
import java.awt.Paint;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.BarRenderer;
CategoryPlot myPlot = chart.getCategoryPlot();
BarRenderer categoryItemRenderer = myPlot.getRenderer();
plot = chart.getPlot();
renderer = plot.getRenderer();
data = chart.getPlot().getDataset();
keys = data.getRowKeys();
Color[] c={
new Color(0x4784D7),
new Color(0x1F4F8F),
new Color(0xDBE7A5),
new Color(0xC8DB78),
new Color(0x7D838F),
new Color(0x272B39)
for (int i=0;i<keys.size();i++)
int j=(i*2);
g = new GradientPaint(0, 0,c[j],10, 0, c[j+1],true);

Here is the final result

Horizontal Bar Chart

Horizontal Bar Chart

Download the .PRPT file from here: http://tinyurl.com/gradientbar

Need PDF as output to your email, website???

Last night I was just reading some blogs and I come across one website which was very interesting one. First I thought I must be some kind of spam maker or something. But I couldn’t stop myself when I say some screenshot that how this website works.

It was pretty simple to understand what these website do. As a designer I always want some solution like this, to give my colleagues who always come with some kind of content to convert in PDF.

Trust me still people don’t know much tool which make their life easier.

Just imagine when you are traveling and when you are accessing something on web or in your email and want to convert that in PDF to send someone. You have to wait till you get your system and then you go all the way down to convert your content in pdf.

This website which I’m going to show will do the same job and that too free of cost.


If you want to convert your any email in PDF format then send original mail on pdfconvert@pdfconvert.me and you will get your email which you want to convert in PDF as a PDF attachment.


Mail to pdf


Mail back



PDF as attachment

Ok so now you might have question like, what will happen when I have an attachment in my email. Of course above email will not work but you can convert this also when you send this mail on attachconvert@pdfconvert.me

Now the website feature will not end here. If you want to convert a webpage in PDF then just type the URL in a mail body and send this email to webconvert@pdfconvert.me and you will get that web page in PDF format.

Information which this websites collects

According to this website policy they say:

This service keeps a copy of the messages you send to it only as long as is required to convert them to PDF and return them to you.

Some metadata from the message is retained on the server in logs or database records, primarily sender email and subject/URL (to assist in debugging in case of problems).

How to read and write cookies with Adobe Flash

This is one of my very old blog which i have written on Blogger but due to some issues with blogger some on my friend asked me to re-share this on some better blog side. So I’m here with new blog side with new topics.

So lets start here with the cookies with Adobe Flash

After searching tones of pages on Google I really got disappointed that Adobe Flash is not having any capability to talk directly with cookie. Whenever I search for “cookies with Adobe Flash” people always talks about ShareObject or super cookies. I know ShareObject very well and also know the usage of shareObject.

Recently on one of my project, my client asked me to read and write cookie through flash .swf file. First I try to play with ShareObject, but when I got the requirement like they need to play with social networking websites cookies, I felt ShareObject is not the right thing which I should use on this project. Then I start searching about Cookie with flash but didn’t got any luck.

Finally I created this work around to achieve the desire result. Now I would like to share this solution for those who don’t want to use ShareObject and want to play with cookies.

For this work around I created one HTML page with small JavaScript code. But first we’ll create a basic flash swf file

Your Flash File should looks like this.

Now go to Flash and create one new document with “200×350” Action Script 1.0 create 2 input text field on stage and give var name as “name” and “txComment“.

Also create 2 Buttons on stage one for “Write Cookie” and second one for “Read Cookie”


Adobe Flash

Now write this code on “Write Cookie” Button

on (release)
  getURL("javascript:cookit(\'name\',\'" + /:name + "\',\'txComment\',\'" + /:txComment + "\')", "");

Now write this code on “Read Cookie” Button

on (release)
  getURL("javascript:if(document.cookie.length<1){alert(\'No cookie for%20this site.\')}else{alert(\'Your Cookie is:\'+document.cookie)}");

Note: you can choose any file name but make sure you use same swf name in html code also

Now save your flash file as flookies.Fla and render .swf file

HTML page with JavaScript

<script type="text/javascript">
 exLenght = 9
 exDate = new Date

function cookit() {
 for(i=0;i<cookit.arguments.length;i++) {
  ckThing = cookit.arguments[i] + '=' + cookit.arguments[i+1]
  document.cookie = ckThing + '; expires=' + exDate.toGMTString() + '; path=/'

ckStr = "?"  
 if(document.cookie != "") {
  theCook = document.cookie.split("; ")
  for (i = 0; i < theCook.length; i ++) {
   ckStr += theCook[i] + "&"

Open you HTML page in IE and test also check your Temporary Internet folder and fond the cookie.