Thursday, September 13, 2012

CGG - Putting CCC charts in Pentaho reporting / other tools

This has been a long standing blog post. CGG has been around for ages now, it's even in Pentaho platform core, and only a few knew about it.


CGG stands for Community Graphics Generator. Although it even has it's own homepage,  I never had the chance to blog about it. It's a somewhat hardcore plugin: it's basically able to execute on the server side custom scripts (java / javascript) that outputs images that can be used in external systems.


One of the most useful use cases is to be able to export CCC charts to images (png or svg) - either to allow a user the ability to download it, or to include it in Pentaho Reporting or any other of those tools


Here's an example of how it works. Imagine you develop for your users a great looking dashboard, almost as good looking as one of the UIs we develop :) :


 (This was the dashboard we developed in a recent Ctools training course in Orlando, Pentaho headquarters)

As you can see, we went to some extent, exploring CCC capabilities, to fine tune the charts. Now we want to be able to use that line chart to PRD. Even though CGG does not have a UI and doesn't aim to be user friendly, CDE has a way to make the bridge to it, using some hidden features.

Going straight to the point. In CDE, press shift-G. That will open the CGG window (as a side reference, press shift-? to see other very useful keyboard shortcuts):


 If you ever used this feature before, you'll notice this screen is a little different. We just added some more features, namely the ability to automatically get the url that generates that image from the outside - even I always struggled to find the right url. This is already available in the dev builds and will be released in the next stable version.

You'll be able to see that you can set some options there, namely the outputType, that currently can be either png or svg and you may need to change the server url if are developing in a sandbox and want to publish it to a server.  I actually thought svg support was broken in PRD but just tested it and that seems to be fixed, so take advantage of that feature.

One other thing to note is that you must take care of authentication. Either you pass the extra arguments &userid=joe&password=password or you allow that url to be accessible with no password, or whatever.

If you save your dashboard and try that url, this is what you'll get:


This is what CGG is all about, and there's tons of engineering work underneath to allow this "simple step" to work with just one keystroke.

Now it's gets very obvious what to do. Open PRD, add an image component, and put that url (don't forget authentication)


You'll also want to check the blog post I did a while back about using CDA datasources in PRD. In the meanwhile, in recent versions of PRD (4.5 and above) you don't need to download the CDA datasources, all you need to do is enable the experimental features in Edit -> Preferences -> General -> Enable Experimental Features.

To render this report from the server, you'll need to copy to pentaho/WEB-INF/lib/ the file pentaho-reporting-engine-classic-extensions-cda-*.jar that you'll find in PRD library directory.

There's another feature of CGG. You can pass parameters to the query, by adding &paramParameterName=ParameterValue  to the url. And that can be exposed from PRD too.

Just create a prompt the usual way. On my sample, the parameter is called a month, and since the query is already on the dashboard too, I just need to select it to build the prompt in the prpt.

However, in order to make the call with the new parameter, we can't use the image component anymore, and use the image-field instead.

For that, we need to create a formula that will build that url. Here's the sample formula I used:

="http://127.0.0.1:8080/pentaho/content/cgg/Draw?script=/SyncOrlando/Lab12/lineChart.js&outputType=png&userid=joe&password=password&parammonthParameter="&URLENCODE([month])

 The URLENCODE function allows us to be sure that our parameters will reach the server properly. In the end, we should have a report looking like this:


 Advanced topic: If you make reports with a lot of charts (you can even have cgg rendering a chart per line) you'll soon find out that your report starts to take a really long time to render. There's an explanation for it: PRD does a lot of passes to better determine the final layout. Since CGG doesn't support the HEAD request method, PRD won't get the appropriate info regarding cache, resulting in a bunch of requests for the image. Fortunately, Thomas Morgner allowed is a workaround to this issue, by changing a behavior in libloader. In your loader.properties file (located in WEB-INF/classes for the server or create it under prd/resources dir for the report designer) add the following lines:

# Controls the minimum time between HEAD requests regardless of
# the date -headers given by the response object.
org.pentaho.reporting.libraries.resourceloader.config.url.FixedCacheDelay=500000

# Fixes the date headers by simply using Date.now() as mod-date.
# This will break the HTTP specs and thus it is disabled by default.
org.pentaho.reporting.libraries.resourceloader.config.url.FixBrokenWebServiceDateHeader=true
This particular feature will be available in Pentaho Reporting 3.9.1 (or you'll have to compile your own)

And this is what it looks from the Pentaho BI server:


Cheers


-pedro
  



4 comments:

  1. Great post Pedro, this was very informative! I came across your blog while I was reading articles online about business intelligence and I'm happy I did because you have definitely shared some interesting information with us. Thank you for sharing this with us!

    ReplyDelete
  2. Hi
    I am new to cde and i want to export dashboards in pdf. I have a problem: I dont want to pass the authentication parameters(username and password)in the url to the report designer from cde because i want all the users of the bi-server to access that report and not a specific one. Please let me know if there is any way if i can pass the dashboard image and embed it in report designer report without passing username and passowrd as arguments in the url.
    I am stuck on this problem for days now.I tried all the ways but none is working for me.
    Help me please

    ReplyDelete