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.
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.
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.