Codeigniter: Intergrating OpenFlashCharts
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.
So, download the zip file and extract the files to the relevant folders of your CI install. The assets folder should go to wherever you put your stuff like images and javascript files. Just make sure you change the view to reflect the correct path. I put my assets in the root of my webserver folder, and I access my CI through http://dev.ci/.
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, http://dev.ci/charts/get_data.
Inside 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…

In: PHP Tutorials · Tagged with: charts, codeigniter, openflashcharts


Permalink
[...] tipos de implementación que acepta (php, javascript, .Net, java, python, etc). También os dejo un enlace a un artículo que detalla como trabajar con ella desde [...]
Permalink
Codeigniter: Intergrating OpenFlashCharts…
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…
Permalink
thanks.
i ‘ve used OFC on my project.
it realy easy to use and custom..
Permalink
[...] I decided to switch to FusionCharts because I found it very well documented and it easily integrated into Codeigniter, much more so than OpenFlashCharts (which needed a wrapper class). [...]
Permalink
[...] Series andrewroland zend lucene librarycodeigniter 2.0 workshoplearncodeigniter basics Sponsors Top Rated TutorialsUsing Elliot Haughin's Twitter API with Codeigniter Part 2 (2 votes)CodeIgniter Active Record class and INSERT IGNORE (2 votes)Codeigniter Project Development from scratch to app Part 6 (2 votes)Tags2.0 active record ajax amplio.ch andrewroland.com api askaboutphp beginner class CMS codesamplez controller country db dragffy.com drop down egypt error flashdata form from scratch helper html index.php install jquery login lucene MVC net.tutsplus profiler reactor registration search session simplycodeigniter twitter upload URL validation variables view views workshop zend Sponsors LinksCodeigniter: Intergrating OpenFlashCharts [...]
Permalink
[...] Integrating OpenFlashCharts [...]
Permalink
[...] Integrating OpenFlashCharts [...]