When OpenFlashChart 2 came out, all the CI stuff, using a plugin and creating the charts from CI went down the toilet because the author did the smart thing and created classes in different files.
I searched the net for a solution and didn’t found one. So my question is:
Has anyone made a plugin for OpenFlashChart v2 for Codeigniter?
If not to solve your problem quickly all you need to do is use your view file to render the chart. So in your view file just write:
<?
include ('OFC/php-ofc-library/open-flash-chart.php');
//Defaults
$toolTip = '#val# of #total#<br>#percent# of 100%';
$title1 = new title( "Top Artisti" );
$pie1 = new pie();
$pie1->set_alpha(0.6);
$pie1->add_animation( new pie_bounce(8) );
$pie1->add_animation( new pie_fade() );
$pie1->set_tooltip( $toolTip );
$pie1->set_colours( array('#D544A2','#9408E0','#E25374') );
foreach($DB_FROM_CONTROLER->result() as $row)
{$pieArr1[] = new pie_value(intval($row->DBROW1), $row->DBROW2);}
$pie1->set_values( $pieArr1 );//Pie 1
//Pie 1
$chart1 = new open_flash_chart();
$chart1->set_bg_colour('#EEEEEE');
$chart1->set_title( $title1 );
$chart1->add_element( $pie1 );
$chart1->x_axis = null;
?>
<|script type="text/javascript" src="OFC/js/json/json2.js"><|/script>
<|script type="text/javascript" src="OFC/js/swfobject.js"><|/script>
<|script type="text/javascript">
swfobject.embedSWF("OFC/open-flash-chart.swf", "my_chart_1", "400", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_1"});
function ofc_ready() {/*alert('ofc_ready');*/}
function get_data_1(){return JSON.stringify(data_1);}
function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } }
var data_1 = <?php echo $chart1->toPrettyString(); ?>;
<|/script>
Here:
foreach($DB_FROM_CONTROLER->result() as $row)
{$pieArr1[] = new pie_value(intval($row->DBROW1), $row->DBROW2);}
I’m just converting the query data to the my PIE chart array.
Now all you need to do is to insert a div tag where the chart should be showed:
<div id="my_chart_1"></div>
And this is it, works like a charm. I know is the most stupid way and wrong way to implement this but until I figure out how to make the chart lib as a plugin perhaps this will be helpful.
If you need help with the formating just consult the manual for the chart lib.
NOTE: <|/script> remove the | sign , I have add it to show correctly.
