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.

Download: download icon

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.

OFC Test Chart

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…

Dilbert Pie Chart

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • Propeller
  • Reddit
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
Posted on November 6, 2009 at 1:12 pm by Eldee · Permalink
In: PHP Tutorials · Tagged with: , ,

7 Responses

Subscribe to comments via RSS

  1. [...] 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 [...]

  2. Written by php-html.net on November 8, 2009 at 4:24 am
    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…

  3. Written by syabac on July 11, 2010 at 5:28 pm
    Permalink

    thanks.
    i ‘ve used OFC on my project.
    it realy easy to use and custom..

  4. [...] 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). [...]

  5. [...] 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 [...]

  6. Written by Free/Open Source CodeIgniter Scripts « shivamtailor on October 11, 2011 at 7:16 pm
    Permalink

    [...] Integrating OpenFlashCharts [...]

  7. [...] Integrating OpenFlashCharts [...]

Subscribe to comments via RSS

Leave a Reply