PHP 파일로 만든 json 데이터를 다른 스크립트로 구문 분석하고 그 값을 하이 차트에 표시하려고합니다.성공없이 JSON 데이터를 Highcharts로 전달하려고합니다.
<?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);
},
});
}
제가 생성 방법 JSON 데이터를 생성
내 data.php이있다 세리는 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 날짜 요구 될 ** 시대 시간에 간다 'string') 값은 숫자 ('float' 또는'int')가되어야합니다. 모든 것이 문자열 –
입니다. @ 내 업데이트를보세요. – Alexandros
오류 14가 발생하지 않습니다! – Alexandros