drwjv28028 2013-04-01 19:33
浏览 123

Highstock不显示图表

I have php file which produce data in JSON format get_json.php and file where I want to display chart grafik.php.

Code in 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);

?>

Output of JSON get_json.php [[1364463576000,46906],[1364463578000,50379],[1364463580000,33733],[1364463582000,5612], [1364463981000,14213],[1364464007000,11208],[1364490137000,38047],[1364665254000,14964],[1364665256000,11443],[1364665257000,9005],[1364665259000,5283],[1364665260000,1731]]

Code in 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>

I dont know where I did a mistake, if anybody see some mistake please help me to solve this. I am trying to do chart where on X-axis will be time and on Y-axis proper value.

  • 写回答

1条回答 默认 最新

  • doulu3808 2013-04-02 07:50
    关注

    I got your data working:

    $('#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
         }
     }]
    });
    

    http://jsfiddle.net/3A3bK/

    I had to change the fist line from:

    $('#container').highcharts('StockChart', {
    

    to

    $('#container').highcharts({
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?