我有php文件,它以JSON格式 get_json.php 生成数据,并且我想显示图表 grafik.php 。
get_json.php
中的代码<?php
include('config.php'); //connection to DB
$r=("SELECT * FROM data");
$result=mysql_query($r);
while($row = mysql_fetch_array($result)){
$date= strtotime($row['cas'])*1000; //time in format 2013-03-21 16:23:11
$values=hexdec($row['data']); // hex values to decimal
$array[]=array($date, $values);
}
echo json_encode($array);
?>
输出JSON get_json.php [[1364463576000,46906],[13644635780000,50379],[1364463580000,53712],[1364463582000,5612],[1364463981000,14213],[1364464007000,11208],[1364490137000,38047],[1364665254000,14964],[ 1364665256000,11443],[1364665257000,9005],[1364665259000,5283],[1364665260000,1731]]
grafik.php
中的代码<html>
<head>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
</head>
<body>
<script>
$(function() {
$.getJSON('http://localhost/testing10/get_json.php', function(data) {
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 1
},
title : {
text : 'AAPL Stock Price'
},
series : [{
name : 'AAPL Stock Price',
data : data,
marker : {
enabled : true,
radius : 3
},
shadow : true,
tooltip : {
valueDecimals : 2
}
}]
});
});
});
</script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
我不知道我在哪里犯了错误,如果有人看到一些错误请帮我解决这个问题。 我试图做图表,其中X轴将是时间和Y轴正确值。
答案 0 :(得分:0)
我的数据正常运行:
$('#container').highcharts({
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL Stock Price',
data: [
[1364463576000, 46906],
[1364463578000, 50379],
[1364463580000, 33733],
[1364463582000, 5612],
[1364463981000, 14213],
[1364464007000, 11208],
[1364490137000, 38047],
[1364665254000, 14964],
[1364665256000, 11443],
[1364665257000, 9005],
[1364665259000, 5283],
[1364665260000, 1731]
],
marker: {
enabled: true,
radius: 3
},
shadow: true,
tooltip: {
valueDecimals: 2
}
}]
});
我不得不改变第一行:
$('#container').highcharts('StockChart', {
到
$('#container').highcharts({