Fusion Chart plugin for CodeIgniter
This is my own version in creating a fusion chart plugin for CodeIgniter. I tried to make it as simple as possible. Enjoy…
Step 1: Get your copy of free fusion chart here. http://www.fusioncharts.com/free/Gallery.asp?gMenuItemId=3
and extract all files.
Step 2: Copy the Charts folder to anywhere you like. I’ve set mine to /charts/ on the CI root directory.
Step 3: Copy the FusionCharts.js under the JSClass folder to anywhere you like. I’ve set mine to /javascripts/ on the CI root still.
Step 4: Copy everything from Code/PHPClass/Includes and put it inside system/plugins/fusion/.
Step 5: Build your CI Plugin. I named my fusion_pi.php and save it on system/plugins/:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function FusionCharts( $chart_type='', $width = "300", $height = "250" ){
require_once( 'fusion/FusionCharts_Gen.php' );
$FC = new FusionCharts( $chart_type, $width, $height );
$FC->setSWFPath("images/fusioncharts/");
return $FC;
}
?>
Using the plugin:
Note: You need to include FusionCharts.js on your HTML File preferably on the header part.
function mychart(){
$this->load->plugin( 'fusion' );
$FC = FusionCharts("Column3D","520","200");
$arrData = array( 500, 269, 254, 895, 633);
foreach( $arrData as $i=>$data ){
$FC->addChartData( $data );
}
$strParam="numberSuffix=%; formatNumberScale=0; decimalPrecision=0; xAxisName=Integrated Process Average Score; animation=1";
$FC->setChartParams($strParam);
$FC->setChartMessage("ChartNoDataText=Chart Data not provided; PBarLoadingText=Please Wait.The chart is loading...");
return $FC->renderChart(false,false);
}
For more information in using Fusion Chart please see documentation included.
20 comments
Trackbacks/Pingbacks
- How to use FusionCharts with CodeIgniter? - [...] http://www.ikawka.com/2008/12/fusion-chart/ [...]






Great job – very useful indeed!
/Moefelt
Hi, would you mind to post the view ? o even a complete example
i cant figure out how to use it in the view
The second part of the code is a portion of the controller already, use it with your view and your golden.
Ok, so i have messed around with the script to get it to work properly, but i have a question.
if i do this
$FC->addChartData(‘500′);
it will show the data correctly, one bar with the value of 500, how do i name it though? I have looked through the docs quite a bit and cant find an answer.
Your code above copied and pasted does not work, it’s show 5 plots but none with correct values, all with the word “ARRAY” as the value.
Thanks in advance.
typo in your code above
yours
foreach( $arrData as $i=>$data ){
fixed
foreach( $arrData as $i=>$arrData ){
or you can change the:
$FC->addChartData( $arrData );
to
$FC->addChartData( $data );
my bad ^_^
I have also taken the time to simply echo it out in a view as the first person asked, and to also put everything in the CI file structure so that people can copy and paste the system over.
(i always move my application folder out of my system folder so if you have a stock install of CI please make sure you put the folders in the correct spots.)
http://www.o5media.com/share/graphs.zip
Nice! tnx a lot for sharing.
Np, if you want to post the updated code publicly, thats more than ok, the one spot that i spent a lot of questioning was how to attach a name to a value. I couldn’t figure it out with
This method :
$FC->addChartData( $arrData );
But this works, and is the the zip i attached above:
$arrData[0][0] = ‘Jan’;
$arrData[1][0] = ‘Feb’;
$arrData[2][0] = ‘Mar’;
$arrData[3][0] = ‘Apr’;
$arrData[0][1] = 200;
$arrData[1][1] = 400;
$arrData[2][1] = 200;
$arrData[3][1] = 300;
$FC->addChartDataFromArray( $arrData);
I am going to hook it up to a database this week to plot some basic stats for a client lead system i’m building for a client. I’ll post the code and sqldump with some working examples when it is done.
Me neither, so I decided to output xml and javascript instead.
how u do that ?
i followed all steps mentioned but did not have any view. instead had all these things in my controller class. The output comes as “Chart”
. What could i be missing?
did u include the .js file to the output?
Thats very good share from You.
Thank you.
Hey friends, please check your path of $FC->setSWFPath(“”); in fusion_pi.php which shows in first block.
set you swfs path to it.
Thats very good share from You.
Thank you.
yeah I have copy swfs folder in to my project’s root folder. in charts/Charts/ all swfs
and set $FC->setSWFPath(“../charts/Charts/”);
It works
I did exactly what you mentioned. But I am getting
one error. FusionCharts is not defined. (I added the .js file to the view. But It is not recognizing.)
Please help me.
Simple way to use Fusion chart in codeigniter.
Add FusionCharts.js file in your view.
copy the charts folder into your site root
And add the below code for chart.
FusionCharts.
var chart = new FusionCharts(“Charts/FCF_MSColumn3DLineDY.swf”, “ChartId”, “600″, “350″);
chart.setDataURL(“Charts/Col3DLineDY.xml”);
chart.render(“chartdiv”);
What fixer wonderful post! Thank ego so so forwards sharing Ivie & Grace!
plenty
Awesome layout, i do computer repair. Maybe we could swap some services.