ハイストックチャートにデータをロードするのに問題があります。
私の json.php は、サンプルの MySQL データベースを呼び出し、次のようになります。
$result = mysql_query("SELECT UNIX_TIMESTAMP(date)*1000 AS timestamp,value from sample") or die('Could not query');
if(mysql_num_rows($result)){
echo 'Test';
$first = true;
$row=mysql_fetch_assoc($result);
while($row=mysql_fetch_row($result)){
if($first) {
$first = false;
} else {
echo ',';
}
$json_str = json_encode($row, JSON_NUMERIC_CHECK);
echo $json_str;
}
if(array_key_exists('callback', $_GET)){
$callback = $_GET['callback'];
echo $callback. '('.$json_str.');';
}
} else {
echo '[]';
}
mysql_close($db);
Json.php を呼び出す私の index.htm は、サンプルの highstock テンプレートからのものです。参照と一致するように getJson を変更しただけです。これがコードです。どんな助けでも大歓迎です、ありがとう。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON('json.php', function(data) {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 1
},
title : {
text : 'Test'
},
series : [{
name : 'Test',
data : data,
marker : {
enabled : true,
radius : 3
},
shadow : true,
tooltip : {
valueDecimals : 2
}
}]
});
});
});
</script>
</head>
<body>
<script src="js/highstock.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
また、私のjsonは次のように解析されます:
テスト[1370899026000,10]、[1370899026000,4]、[136817426000,11]、[1370899026000,12]、[137089026000,13]、[1370899026000,11] 1370899026000,13]、[1370899026000,9]、[137089026000,14]、[1370899026000,12]、[137089026000,10]、[1370899026000,15] 9]、[1370899026000,11]、[1370899026000,7]、[1370899026000,3]、[1370899026000,6]、[137089026000,0]、[1370899026000,11] 、[1370899026000,7]、[1370899026000,8]、[137099026000,8]、[1370899026000,9]、[1370899026000,13]、[1370899026000,11]、[137089026000,10]、[1370899026000,11]、 1370899026000,12]、[1370899026000,12]、[1370899026000,11]、[1370899026000,13]、[137089026000,10]、[1370899026000,8] 12],[1370899026000,14],[1370899026000,9],[1370899026000,9],[1370899026000,12]、[1370899026000,13]、[1370899026000,4]、[1370899026000,4]、[1370899026000,4]、[137089026000,13]、[1370889026000,5] 、[1370899026000,10]、[1370899026000,22]、[1370899026000,9]、[1370899026000,5]、[137089026000,9]、[1370899026000,10]、[137089026000260099070707070702600990,00026000,00026000,00026000,000 1370899026000,10]、[1370899026000,5]、[137089026000,7]、[1370899026000,9]、[1370899026000,9]、[1370899026000,10]、[137089026000,0006000,6000,6000,6000,6000,6000 6]、[1370899026000,12]、[1370899026000,7]、[1370899026000,12]、[1370899026000,8]、[1370899026000,13]、[1370899026000]、[137089026000,9026000]、[1370899026000] 、[1370899026000,7]、[1370899026000,9]、[137099026000,12]、[1370899026000,13]、[137089026000,9]、[1370899026000,10] 1370899026000,12]、[1370899026000,13]、[1370899026000,11]、[1370899026000,13]、[1370899026000,11]、[1370899026000,13]、[1370899026000,9]、[1370899026000,14]、[1370899026000,12]、[137089026000,10]、[1370899026000,15] 、9]、[1370899026000,11]、[1370899026000,7]、[1370899026000,3]、[1370899026000,6]、[137089026000,0]、[1370899026000,11] ]、[1370899026000,7]、[1370899026000,8]、[1370899026000,8]、[1370899026000,9]、[137089026000,13]、[1370899026000,11] [1370899026000,12]、[1370899026000,12]、[1370899026000,11]、[1370899026000,13]、[137089026000,10]、[1370899026000,8,000]、 、12]、[1370899026000,14]、[1370899026000,9]、[1370899026000,9]、[1370899026000,12]、[137089026000,13]、[1370899026000]、[137089026000] ]、[1370899026000,13]、[1370899026000,5]、[1370899026000,10]、[1370899026000,4]、[1370899026000,10]、[1370899026000,22]、[1370899026000,9]、[1370899026000,5]、[1370899026000,9]、[1370899026000,10]、[1370899026000]80,90[26003,6]