使用ORACLE数据的Highchart饼图

时间:2015-02-12 09:06:10

标签: php oracle charts

我正在使用highcharts pir图表,我需要将2维数据数据记录到javascript中,参数接受如下

series: [{
            type: 'pie',
            name: 'Weight',
            data: [
                ['DATA1',   DATA2], //Row 1
                ['DATA1',   DATA2], //Row 2 etc....
            ]
        }]

所以我通过看起来像这样的oracle查询获取所有内容

$i = 0;
    while ($row = oci_fetch_array($buildingOverviewParse)){
        $buildingName = $row['PROJECTNAME'];
        $percentagePerBuilding = $row['PERCENTAGE'];
        $i++;
    }

    $buildingVal[$i] = strval($buildingName);
    $percentageVal[$i] = doubleval($percentagePerBuilding);

并在脚本上

series: [{
            type: 'pie',
            name: 'Weight',
            data: [ buildingValue, percentageValue
            ]
        }]

我没有运气,有人可以帮助我吗?

非常感谢

1 个答案:

答案 0 :(得分:3)

我已经使用另一个名为 getGraphs.php 的页面来获取图表的数据。

在你的highcharts中

series: [{
        type: 'pie',                    
        name: 'Weight',
        data: []
    }]
} 
$.getJSON("getGraphs.php", function(json) {
   if ( json.length != 0 )
    {
        options.series[0].data = json;
        chart = new Highcharts.Chart(options);
    }
    else
    {
       //Show some message that data is empty
    }

});

然后,在getGraphs.php

$result = mysql_query("----Query----"); // Fetch data to display in your chart
$rows = array();
while($r = mysql_fetch_array($result)) {
    $row[0] = $r[0];
    $row[1] = $r[1];
    array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
相关问题