Welcome Guest, Not a member yet? Register   Sign In
Install FusionChart on CI as plugin Plugin
#1

[eluser]Amjith or Cool Coder[/eluser]
Hi,
Note: Please delete space between the links of fusionchart. eg: you will find space after http: (http: //).
http: //www.fusioncharts.com/free/Overview.asp?gMenuItemId=2
If you feels difficult to use it, Please follow below steps.
1. Download Fusionchart http: //www.fusioncharts.com/free/Download.asp?gMenuItemId=5
2. Unzip, Folder
3. Copy folder 'Charts' to root of your CI Project
4. If you are using .htaccess ,
open file and add Charts 'RewriteCond' ,
example will be
Code:
RewriteCond $1 ^(index\.php|Charts)
5. Open folder 'Code/PHP'
You will find a list of folders showing php examples on how to create fusion charts. Its really helpful for development. Before we can add a plugin module to the CI

a. add a new file 'fusionchart_pi.php' on your CI Project folder 'system/plugins/'
add this lines of code to that file

Code:
<?php
function encodeDataURL($strDataURL, $addNoCacheStr=false) {
    if ($addNoCacheStr==true) {
                                if (strpos(strDataURL,"?")<>0)
                                            $strDataURL .= "&FCCurrTime;=" . Date("H_i_s");
                                else
                                            $strDataURL .= "?FCCurrTime=" . Date("H_i_s");
                 }
                return urlencode($strDataURL);
}
function datePart($mask, $dateTimeStr) {
    @list($datePt, $timePt) = explode(" ", $dateTimeStr);
    $arDatePt = explode("-", $datePt);
    $dataStr = "";
    if (count($arDatePt) == 3) {
        list($year, $month, $day) = $arDatePt;
        switch ($mask) {
        case "m": return (int)$month;
        case "d": return (int)$day;
        case "y": return (int)$year;
        }
           return (trim($month . "/" . $day . "/" . $year));
    }
    return $dataStr;
}
function renderChart($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
    if ($strXML=="")
        $tempData = "//Set the dataURL of the chart\n\t\tchart_$chartId.setDataURL(\"$strURL\")";
    else
        $tempData = "//Provide entire XML data using dataXML method\n\t\tchart_$chartId.setDataXML(\"$strXML\")";
                    $chartIdDiv = $chartId . "Div";
                                $render_chart = <<<RENDERCHART
                                                                                        &lt;!-- START Script Block for Chart $chartId --&gt;
                                                                                        <div id="$chartIdDiv" align="center">
                                                                                            Chart.
                                                                                        </div>
                                                                                        [removed]    
                                                                                            //Instantiate the Chart    
                                                                                            var chart_$chartId = new FusionCharts("$chartSWF", "$chartId", "$chartWidth", "$chartHeight");
                                                                                           $tempData
                                                                                            //Finally, render the chart.
                                                                                            chart_$chartId.render("$chartIdDiv");
                                                                                        [removed]    
                                                                                        &lt;!-- END Script Block for Chart $chartId --&gt;
RENDERCHART;
  return $render_chart;
}
function renderChartHTML($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
    $strFlashVars = "&chartWidth;=" . $chartWidth . "&chartHeight;=" . $chartHeight ;
    if ($strXML=="")
        $strFlashVars .= "&dataURL;=" . $strURL;
    else
        $strFlashVars .= "&dataXML;=" . $strXML;
$HTML_chart = <<&lt;HTMLCHART
    &lt;!-- START Code Block for Chart $chartId --&gt;
    &lt;OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  width="$chartWidth" height="$chartHeight" id="$chartId">
        <param name="allowScriptAccess" value="always" />
        <param name="movie" value="$chartSWF"/>        
        <param name="FlashVars" value="$strFlashVars" />
        <param name="quality" value="high" />
        &lt;embed src="$chartSWF" FlashVars="$strFlashVars" quality="high" width="$chartWidth" height="$chartHeight" name="$chartId" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /&gt;
    &lt;/object&gt;
    &lt;!-- END Code Block for Chart $chartId --&gt;
HTMLCHART;
  return $HTML_chart;
}
function boolToNum($bVal) {
    return (($bVal==true) ? 1 : 0);
}
?&gt;
6. Copy 'JSClass/FusionCharts.js' from fussion chart folder to your CI javascripts folder
7. Call plugin on your controller ($this->load->plugin('fusionchart'))
8. Add javascript to your view
9. On your view file,
Code:
&lt;?php echo renderChart(site_url("Charts/FCF_Line.swf"), $XML_DATA, "", "chart1", 230, 130);?&gt;
for line graph
$XML_DATA is the variable where xml data is stored as file. for reference regarding XML formats please refer
http: //www.fusioncharts.com/free/docs/?gMenuItemId=19
10 You are done.

Thanks and hope everything works good.

My next post will be of creating Fusionchart library on CI.
#2

[eluser]Iverson[/eluser]
Great post. I did it differently but this looks cool too. But using "&lt;?=" is a big no-no in the CI community! :bug:
#3

[eluser]Amjith or Cool Coder[/eluser]
[quote author="Iverson" date="1226693511"]Great post. I did it differently but this looks cool too. But using "&lt;?=" is a big no-no in the CI community! :bug:[/quote]

dude, thanks for notification. i have changed it.
#4

[eluser]Iverson[/eluser]
[quote author="Amjith or Cool Coder" date="1226664378"]
Code:
&lt;?php
function encodeDataURL($strDataURL, $addNoCacheStr=false) {
    if ($addNoCacheStr==true) {
                                if (strpos(strDataURL,"?")<>0)
                                            $strDataURL .= "&FCCurrTime;=" . Date("H_i_s");
                                else
                                            $strDataURL .= "?FCCurrTime=" . Date("H_i_s");
                 }
                return urlencode($strDataURL);
}
function datePart($mask, $dateTimeStr) {
    @list($datePt, $timePt) = explode(" ", $dateTimeStr);
    $arDatePt = explode("-", $datePt);
    $dataStr = "";
    if (count($arDatePt) == 3) {
        list($year, $month, $day) = $arDatePt;
        switch ($mask) {
        case "m": return (int)$month;
        case "d": return (int)$day;
        case "y": return (int)$year;
        }
           return (trim($month . "/" . $day . "/" . $year));
    }
    return $dataStr;
}
function renderChart($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
    if ($strXML=="")
        $tempData = "//Set the dataURL of the chart\n\t\tchart_$chartId.setDataURL(\"$strURL\")";
    else
        $tempData = "//Provide entire XML data using dataXML method\n\t\tchart_$chartId.setDataXML(\"$strXML\")";
                    $chartIdDiv = $chartId . "Div";
                                $render_chart = <<<RENDERCHART
                                                                                        &lt;!-- START Script Block for Chart $chartId --&gt;
                                                                                        <div id="$chartIdDiv" align="center">
                                                                                            Chart.
                                                                                        </div>
                                                                                        [removed]    
                                                                                            //Instantiate the Chart    
                                                                                            var chart_$chartId = new FusionCharts("$chartSWF", "$chartId", "$chartWidth", "$chartHeight");
                                                                                           $tempData
                                                                                            //Finally, render the chart.
                                                                                            chart_$chartId.render("$chartIdDiv");
                                                                                        [removed]    
                                                                                        &lt;!-- END Script Block for Chart $chartId --&gt;
RENDERCHART;
  return $render_chart;
}
function renderChartHTML($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
    $strFlashVars = "&chartWidth;=" . $chartWidth . "&chartHeight;=" . $chartHeight ;
    if ($strXML=="")
        $strFlashVars .= "&dataURL;=" . $strURL;
    else
        $strFlashVars .= "&dataXML;=" . $strXML;
$HTML_chart = <<&lt;HTMLCHART
    &lt;!-- START Code Block for Chart $chartId --&gt;
    &lt;OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  width="$chartWidth" height="$chartHeight" id="$chartId">
        <param name="allowScriptAccess" value="always" />
        <param name="movie" value="$chartSWF"/>        
        <param name="FlashVars" value="$strFlashVars" />
        <param name="quality" value="high" />
        &lt;embed src="$chartSWF" FlashVars="$strFlashVars" quality="high" width="$chartWidth" height="$chartHeight" name="$chartId" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /&gt;
    &lt;/object&gt;
    &lt;!-- END Code Block for Chart $chartId --&gt;
HTMLCHART;
  return $HTML_chart;
}
function boolToNum($bVal) {
    return (($bVal==true) ? 1 : 0);
}
?&gt;


My next post will be of creating Fusionchart library on CI.[/quote]

This code is REALLY not CI-ish. Nor is it copy and "pastable". I will try to rewrite it and post this later.
#5

[eluser]Iverson[/eluser]
Nevermind. This is giving me a headache.
#6

[eluser]baradji[/eluser]
I try since 7 days to show my data in fusioncharts with codeigniter.it isn’t work.
but it work when use without codeigniter.

this is whats I make

1) I copie FusionChats in my repository libraries of my root application of codeigniter

2) in my controller,you are

class DevicesStat extends Controller{
function DevicesStat (){
// load controller parent
parent::Controller();
// Charger un model de devicestat
$this->load->model(‘mod_stat/DevicesByTypeMod’);

function byTypeGraphe(){
// charger le plugin de fudion chart
$this->load->library(‘fusioncharts’);
// store data for being displayed on view file
$data[‘devices’]=$this->DevicesByTypeMod->getDevices(); //pour afficher le topten des equipements par type
$data[‘nbDevices’]=$this->DevicesByTypeMod->getNbDevices();
$data[‘title’]=‘equipements par type’;
$data[‘header’]=‘Liste des équipements par type’;
// load ‘users_view’ view
$this->load->view(‘mod_stat/devicesByType_viewGraphe’,$data); //pour afficher le graphique

2) in my model

class DevicesByTypeMod extends Model{

function DevicesByTypeMod(){
// call the Model constructor
parent::Model();
// load database class and connect to MySQL
$this->load->database();
}

public function getDevices()
{
$sql=“SELECT COUNT( * ) AS Nombre_postes,dc.DeviceCategory_Description AS type_device
FROM device d
LEFT JOIN devicecategory dc
ON d.DeviceCategory_ID = dc.DeviceCategory_ID
LEFT JOIN nmid n
on d.device_id = n.object_id
WHERE n.nmid_statusinappliance = ‘Active’
GROUP BY d.DeviceCategory_ID
ORDER BY Nombre_postes DESC”;
$devices=$this->db->query($sql);
return $devices->result_array();

3) in my view deviceByType_viewGraphe.php

- I include the file include(“system/application/libraries/FusionCharts/Code/PHP/Includes/FusionCharts.php”);

I call the javascript file

[removed][removed]
&lt;style type=“text/css”&gt;

- $strXML = “<chart caption=‘Nombre de postes ’ subCaption=’ par type’ pieSliceDepth=‘40’ showBorder=‘1’ formatNumberScale=‘0’ numberSuffix=’ postes’>”;
// Fetch all devices records
foreach($devices as $device)
{
$strXML .= “<set label=’” . $device[‘type_device’] . ”’ value=’” . $device[‘Nombre_postes’] . ”’ >”;
}

//Finally, close <chart> element
$strXML .= “</chart>”;

echo renderChart($typeGraphique, “”, $strXML, “FactorySum”, 1200, 1000, false, false);

————————————————————————-

but in the result, I have no graph, but a simple word “Chart” :hehe:

Can somebody help me quickly, I’m very worry

Thx
#7

[eluser]naim[/eluser]
I have the same bug also.

Anybody?
Plz.
#8

[eluser]baradji[/eluser]
I resolved the problem with base_url()

this is my code:

$strXML = "<chart caption='Equipements par Model: ".$nbre_ligne." modèles' xAxisName='Model Equipement' yAxisName='Nombre' pieSliceDepth='40' showBorder='1' formatNumberScale='0' numberSuffix='' slantLabels = '1' labelDisplay = 'ROTATE'>";
// Fetch all devices records
foreach($devices as $device)
$strXML .= "<set label='" . $device->model . "' value='" . $device->Nombre_postes . "' link='".base_url()."index.php/devicesStat/byModelListe/" . $device->Model_ID . "' />";
$strXML .= "</chart>";

//Create the chart - Pie 3D Chart with data from $strXML
$typeGraphique = base_url()."system/application/libraries/FusionCharts/Code/FusionCharts/Column3D.swf";
echo renderChart($typeGraphique, "", $strXML, "FactorySum", 1100, 600, false, false);




Theme © iAndrew 2016 - Forum software by © MyBB