未显示融合饼图数据(无数据显示)

时间:2014-05-26 07:50:29

标签: javascript ajax xml codeigniter fusioncharts

我已经编写了一个示例代码来显示codeigniter中的示例饼图数据,但是我得到没有数据显示在显示div中,控制器功能正常,返回正确的xml,建议

我的控制器功能

   function getpieData() {
        $FC = $this->Charts();
        $strXML = "caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units' animation=1";
        $FC->setChartParams($strXML);
        $strQuery = $this->db->get('Factory_Master');
        $result = $strQuery->result();
        if ($result) {
            foreach ($result as $data) {
                $strQuery = $this->db->query("select sum(Quantity) as TotOutput from Factory_Output where FactoryId=$data->FactoryId");
                $result2 = $strQuery->result();
                foreach ($result2 as $ors) {
                    $FC->addChartData( $ors->TotOutput,"label=".$data->FactoryName);     
                }

                print $FC->getXML();
            }
        }
    }

xml返回

<chart caption='&apos;Factory Output report&apos; subCaption=&apos;By Quantity&apos; pieSliceDepth=&apos;30&apos; showBorder=&apos;1&apos; formatNumberScale=&apos;0&apos; numberSuffix=&apos; Units&apos; animation=1'  ><set  value='644' label='Factory 1'  /><set  value='2644' label='Factory 2'  /><set  value='1252' label='Factory 3'  /></chart>

我的Html

 <script>
     function drawPieChart(chartSWF, strXML, chartdiv) {
    //Create another instance of the chart.
    var chart = new FusionCharts(chartSWF, "FactorySum", "600", "300", false, false); 
    chart.setDataXML(strXML);
    chart.render(chartdiv);
   }
   $().ready(function){
    $.get("<?php echo base_url();?>main_dashboard/getpieData/",function(data) {
        drawPieChart("<?php echo base_url();?>charts/Pie3D.swf", data, "gen-chart- render");
    });

}
</script>   


<div id="gen-chart-render">

                    <center>

                    </center>

                </div>

1 个答案:

答案 0 :(得分:0)

从控制器生成的XML似乎格式不正确。

如果使用$ FC-&gt; setChartParams()方法设置属性,则需要将它们作为单个字符串传递,并使用分隔符分隔属性列表。

参考。代码:

 $strXML = "caption=Factory Output report;subCaption=By Quantity;pieSliceDepth=30; showBorder=1;formatNumberScale=0;numberSuffix=Units;animation=1";
 $FC->setChartParams($strXML);

有关详细信息,请参阅Link