我有 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],[1364463578000,50379],[1364463580000,33733] 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 轴上的正确值的图表。