Yes I know, it has been some time since I last posted anything on the site. Things have just been crazy at work, trying to get up to speed on using Pentaho for a major project. In fact, I might start posting some Pentaho related topics in the future. There’s definitely a need for more help and guides on using Pentaho for beginners.
Anyway, one of the things on the project was to pull data from Pentaho and display it inside OpenFlashCharts on a CI platform. If you don’t know what OpenFlashCharts is, go visit the website. It’s a pretty awesome kit.
There’s been quite a bit of chatter on the net about integrating CI with OpenFlashCharts, but ever since version 2 came out there have been more questions about how to do it.
In the new version of OpenFlashCharts, it uses the JSON format to describe what type of chart to render in the flash object. OFC comes with a bunch of libraries (in various programming languages) which will generate the JSON format for the flash object. For PHP, the kit comes with the generic PHP version and a PHP5 version.
Somebody by the name of Thomas did managed to stitch OpenFlashCharts 2 with CI and he posted it up on the CI wiki. So kudos to Thomas (whoever you are) for making my life easier. If you like you can download his library and give it a spin.
For Thomas, he used the PHP5 libraries of OpenFlashCharts, which unfortunately is a bit incomplete. I wasn’t able to generate more advance graphs such as Hollow Areas, Dotted lines etc. The flash object gave me an ‘infinity’ error. After some investigation, I found that the OFC PHP5 libraries are not generating the same JSON as the generic PHP version. Taking a page out of his book, I modified his library to work with the generic PHP version instead.
One advantage of doing this is that suddenly, you can apply all the tutorial codes on the OFC website because they were written for the generic PHP library and not the PHP5 version.
When I run the
http://dev.ci/charts, I would get this graph with 3 data lines.
So how does it all work?
The OFC library,
php-ofc-library and the
OpenFlashChartLib.php can now be accessed by calling the load library call.
$this->load->library('OpenFlashChartLib', NULL, 'OFCL');
If you look inside the view folder for
chart_view.php, you can see where the OFC flash object is getting its JSON feed from,
get_data() function of the charts controller, it’s basically the same code as the tutorial at http://teethgrinder.co.uk/open-flash-chart-2/data-lines-2.php
The difference here is that instead of calling the
$chart = new open_flash_chart();
I’m now doing
$chart = $this->OFCL->create('open_flash_chart');
to perform the same instantiation but through the OpenFlashChartLib (OFCL) library.
So, just change all the object instantiation call accordingly, and the graph should show up nice and neat.
Here’s Dilbert to close out…