我使用的是highcharts pir chart,我需要将二维数据数组记录到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
]
}]
我在这方面运气不好,有人能帮帮我吗?
非常感谢
我使用了另一个名为getGraphs.php的页面来获取图表数据。
在你的高点
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);