Welcome Guest, Not a member yet? Register   Sign In
How do I integrate Fusion Chart in CI?
#4

[eluser]n0xie[/eluser]
fusionchart_pi.php continued

Code:
//renderChartHTML function renders the HTML code for the JavaScript. This
//method does NOT embed the chart using JavaScript class. Instead, it uses
//direct HTML embedding. So, if you see the charts on IE 6 (or above), you'll
//see the "Click to activate..." message on the chart.
// $chartSWF - SWF File Name (and Path) of the chart which you intend to plot
// $strURL - If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
// $strXML - If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
// $chartId - Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.
// $chartWidth - Intended width for the chart (in pixels)
// $chartHeight - Intended height for the chart (in pixels)
// $debugMode - Whether to start the chart in debug mode
function renderChartHTML($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight, $debugMode=false,$registerWithJS=false, $setTransparent="") {
    // Generate the FlashVars string based on whether dataURL has been provided
    // or dataXML.
    $strFlashVars = "&chartWidth;=" . $chartWidth . "&chartHeight;=" . $chartHeight . "&debugMode;=" . boolToNum($debugMode);
    if ($strXML=="")
        // DataURL Mode
        $strFlashVars .= "&dataURL;=" . $strURL;
    else
        //DataXML Mode
        $strFlashVars .= "&dataXML;=" . $strXML;

    $nregisterWithJS = boolToNum($registerWithJS);
    if($setTransparent!=""){
      $nsetTransparent=($setTransparent==false?"opaque":"transparent");
    }else{
      $nsetTransparent="window";
    }
$HTML_chart = <<&lt;HTMLCHART
    &lt;!-- START Code Block for Chart $chartId --&gt;
    &lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="$chartWidth" height="$chartHeight" id="$chartId">
        <param name="allowScriptAccess" value="always" />
        <param name="movie" value="$chartSWF"/>
        <param name="FlashVars" value="$strFlashVars&registerWithJS;=$nregisterWithJS" />
        <param name="quality" value="high" />
        <param name="wmode" value="$nsetTransparent" />
        &lt;embed src="$chartSWF" FlashVars="$strFlashVars&registerWithJS;=$nregisterWithJS" quality="high" width="$chartWidth" height="$chartHeight" name="$chartId" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="$nsetTransparent" /&gt;
    &lt;/object&gt;
    &lt;!-- END Code Block for Chart $chartId --&gt;
HTMLCHART;

  return $HTML_chart;
}

// boolToNum function converts boolean values to numeric (1/0)
function boolToNum($bVal) {
    return (($bVal==true) ? 1 : 0);
}

?&gt;

CONTROLLER
Code:
// $filename is a full path to the xml you want to 'chart'
// in my case http://somedomain.tld/public/xml/somegraph.xml
$data['XML_DATA'] =  $filename;

$this->load->plugin('fusionchart');
$this->load->view('chart_view',$data);

VIEW
Code:
<$cript language="javascript" type="text/javascript" src="/public/admin/js/FusionCharts.js">[removed]
&lt;?php echo renderChart($pathtotheswf, $XML_DATA, "", "chart1", 500, 350);?&gt;

An example XML to get you going. Obviously you could let this render by a generic model
Code:
<graph caption='Newsletter subscriptions' xAxisName='Day' yAxisName='Subscriptions' decimalPrecision='0' formatNumberScale='0'>
<set name='28' value='0' color='5494AF'/>
<set name='29' value='0' color='5494AF'/>
<set name='30' value='0' color='5494AF'/>
<set name='31' value='0' color='5494AF'/>
</graph>

Hope this helps.


Messages In This Thread
How do I integrate Fusion Chart in CI? - by El Forum - 08-27-2009, 01:44 PM
How do I integrate Fusion Chart in CI? - by El Forum - 08-27-2009, 11:02 PM
How do I integrate Fusion Chart in CI? - by El Forum - 08-28-2009, 02:54 AM
How do I integrate Fusion Chart in CI? - by El Forum - 08-28-2009, 02:55 AM
How do I integrate Fusion Chart in CI? - by El Forum - 10-16-2010, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB