嘿伙计们,我无法将我的数据加载到 highstock 图表中。
我的 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],[1368177426000,11],[1370899026000,12],[1370899026000,13],[1370899026000,13] 1370899026000,13],[1370899026000,9],[1370899026000,14],[1370899026000,12],[1370899026000,10],[1370899026000,10],[1370899026000,15] 9],[1370899026000,11],[1370899026000,7],[1370899026000,3],[1370899026000,6],[1370899026000,00 ,[1370899026000,7],[1370899026000,8],[1370899026000,8],[1370899026000,9],[1370899026000,13] 1370899026000,12],[1370899026000,12],[1370899026000,11],[1370899026000,13],[1370899026000,10] 12],[1370899026000,14],[1370899026000,9],[1370899026000,9],[1370899026000,12],[1370899026000,13],[1370899026000,4],[1370899026000,4],[1370899026000,4],[13708990260002600026000,00026000,13] ,[1370899026000,10],[1370899026000,22],[1370899026000,9],[1370899026000,5],[1370899026000,00026000,9] 1370899026000,10],[1370899026000,5],[1370899026000,7],[1370899026000,9],[1370899026000,9],[1370899026000,9] 6],[1370899026000,12],[1370899026000,7],[1370899026000,12],[1370899026000,8],[137089902600026000,00026000,13],[1370899026000,13],[1370899026000,12] ,[1370899026000,7],[1370899026000,9],[1370899026000,12],[1370899026000,13] 1370899026000,12],[1370899026000,13],[1370899026000,11],[1370899026000,13],[1370899026000,11],[1370899026000,13],[1370899026000,9],[1370899026000,14],[1370899026000,12],[1370899026000,10] ,9],[1370899026000,11],[1370899026000,7],[1370899026000,3],[1370899026000,6],[1370899026000],[1370899026000] ],[1370899026000,7],[1370899026000,8],[1370899026000,8],[1370899026000,9],[1370899026000,13],[1370899026000,13],[1370899026000,11] [1370899026000,12],[1370899026000,12],[1370899026000,11],[1370899026000,13],[1370899026000,10] ,12],[1370899026000,14],[1370899026000,9],[1370899026000,9],[1370899026000,12],[1370899026000,13] ],[1370899026000,13],[1370899026000,5],[1370899026000,10],[1370899026000,4],[1370899026000,10],[1370899026000,22],[1370899026000,9],[1370899026000,5],[1370899026000,9],[1370899026000,10],[137026000,10],[137026000,10],[1370],089028900266,