I have implemented Fusion charts into Codeigniter framework with following view. I am creating line chart with provided data in view but, I would like to retrieve this data from same structured database table.
Is there anyway to do it? I will be really appreciated if someone can help me.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
class Chart extends CI_Controller {
function __construct()
{
session_start();
parent::__construct();
if ( !isset($_SESSION['username']) ) {
redirect('admin');
}
}
public function index() {
$this->load->helper(array('url','fusioncharts')) ;
$graph_swfFile = base_url().'public/flash/Line.swf' ;
$graph_caption = 'Results' ;
$graph_numberPrefix = '€ ' ;
$graph_title = 'Results' ;
$graph_width = 600 ;
$graph_height = 250 ;
// Store Name of Products
$arrData[0][1] = "Novomatic";
$arrData[1][1] = "Atronic";
$arrData[2][1] = "Williams";
$arrData[3][1] = "Roulettes";
$arrData[4][1] = "IGT";
$arrData[5][1] = "Interblock";
//Store sales data
$arrData[0][2] = 567500;
$arrData[1][2] = 815300;
$arrData[2][2] = 556800;
$arrData[3][2] = 734500;
$arrData[4][2] = 676800;
$arrData[5][2] = 648500;
$strXML = "<graph caption='".$graph_caption."' numberPrefix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";
//Convert data to XML and append
foreach ($arrData as $arSubData) {
$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
}
//Close <chart> element
$strXML .= "</graph>";
$data['graph'] = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);
//$this->load->view('chart_view',$data) ;
$this->template->load('includes/template', 'chart_view' ,$data);
}
}
Primarily, you would just need to build the XML from the data from your table instead of the array in your existing code.
Sample code can be derived from :
Here is a discussion on the same issue:
http://codeigniter.com/forums/viewthread/136095/#671946
However, you can also use a better data builder and chart generator PHP class provided with FusionCharts pakck.
For detailed reading please refer to FusionCharts Documehtation:
http://www.fusioncharts.com/docs/ > Guide For Web Developers > FusionCharts PHP Class
or
http://www.fusioncharts.com/docs/ > Guide For Web Developers > Using PHP Class