我正在嘗試將由php文件創建的json數據解析到另一個腳本並將其值顯示給一個高圖。嘗試將JSON數據傳遞給Highcharts而沒有成功
我data.php它創建JSON數據是這樣的:
<?php
header("Content-type: application/json");
$dbhost = "localhost";
$dbuser = "db";
$dbpass = "xxxxx";
$dbname = "db";
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$query = "SELECT * FROM monitor_total";
$result = mysql_query($query,$db);
while($row = mysql_fetch_array($result)) {
$date = $row["date"];
$count = $row["count"];
$array[] = array("date" =>$date,"count"=>$count);
}
echo json_encode($array);
?>
的data.php輸出爲:
[{"date":"2012-11-23","count":"582311"},{"date":"2012-11-24","count":"582322"},{"date":"2012-11-22","count":"582121"},{"date":"2012-11-21","count":"581321"},{"date":"2012-11-19","count":"572821"},{"date":"2012-11-20","count":"581321"},{"date":"2012-11-18","count":"582421"},{"date":"2012-11-17","count":"579321"},{"date":"2012-11-16","count":"581321"},{"date":"2012-11-25","count":"558178"}]
內<script>
:
var monitor_graph; // globally available
monitor_graph = new Highcharts.Chart({
chart: {
renderTo: 'graph',
type: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Registered and total players by date'
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Players'
}
},
series: [{
name: 'Total Players',
data: []
}]
});
function requestData() {
$.ajax({
url: 'data.php',
success: function(data) {
$.each(data, function(i,item){
monitor_graph.series[0].setData(??????????);
});
setTimeout(requestData, 1000);
},
});
}
如何創建一個名爲總球員的系列賽,其中x軸的'item.date'和y軸的'item.count'?
請幫幫我!
UPDATE: 我加入這裏面的每個:
monitor_graph.xAxis[0].setCategories([item.date]);
monitor_graph.series[0].setData([parseFloat(item.count)]);
,我現在拿到1分正是因爲我需要它,但有以下錯誤:
Unexpected value NaN parsing y attribute.
相關@ http://stackoverflow.com/questions/12485560/highcharts-returning-error-14日期需求是**劃時代時間**爲'int'(不'string')的值也需要是一個數字('float'或'int')在你的情況下,一切都是字符串 –
看@我的更新請 – Alexandros
我沒有得到錯誤14! – Alexandros