[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
<!-- START Script Block for Chart $chartId -->
<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]
<!-- END Script Block for Chart $chartId -->
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 = <<<HTMLCHART
<!-- START Code Block for Chart $chartId -->
<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" />
<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" />
</object>
<!-- END Code Block for Chart $chartId -->
HTMLCHART;
return $HTML_chart;
}
function boolToNum($bVal) {
return (($bVal==true) ? 1 : 0);
}
?>
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:
<?php echo renderChart(site_url("Charts/FCF_Line.swf"), $XML_DATA, "", "chart1", 230, 130);?>
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.