简体   繁体   English

检索具有多个系列的Highcharts的JSON数据?

[英]Retrieving JSON data for Highcharts with multiple series?

I've been looking through tons of examples but I can't seem to get my code to pull out the data. 我一直在浏览大量示例,但似乎无法获取代码来提取数据。 The chart is blank. 图表为空白。

I have a php file that gives the following: (date, value1, value2) 我有一个提供以下内容的php文件:(日期,值1,值2)

[
["2013-09-15 08:44:37",19.8,8.19],
["2013-09-15 08:47:37",18.4,7.81],
["2013-09-15 08:50:37",18.3,7.78],
["2013-09-15 08:53:37",18.1,7.77]
]

I then have the following code: 然后,我有以下代码:

<!DOCTYPE html>
<head>
  <script src="js/jquery-1.10.2.min.js"></script>
  <script src="js/highcharts.js" type="text/javascript"></script>
  <script>
  var chart;
  $(document).ready(function() {
     var options = {
        chart: {
           renderTo: 'container',
           type: 'line',
        },
        title: {
        },
        xAxis: {
           type: 'datetime'
        },
        yAxis: {
        },
        series: [{
           name: 'val1',
           data: []
       }, {
           name: 'val2',
           data: []
        }]
     };
     $.getJSON('data_day.php', function(json) {
        val1 = [];
        val2 = [];
        $.each(json, function(key,value) {
        val1.push([value.time, value.val1]);
        val2.push([value.time, value.val2]);
        });

        options.series[0].data = val1;
        options.series[1].data = val2;
        chart = new Highcharts.Chart(options);
     });
  });
  </script>
</head>
<html>

I'm trying to use firebug to see where I've gone wrong. 我正在尝试使用萤火虫查看我哪里出了问题。 If I put 如果我放

console.log(key,value) 

under the $.each I can see the data: 在$ .each下,我可以看到数据:

0 ["2013-09-15 08:50:37", 18.3, 7.78]
1 ["2013-09-15 08:53:37", 18.1, 7.77]
2 ["2013-09-15 08:56:37", 18.2, 7.8]

Is there a problem with the 请问有问题吗

val1.push([value.time, value.val1]);

or 要么

options.series[0].data = val1;

Update: Changed it to this and its now working. 更新:对此进行了更改,现在可以使用了。

val1.push([value[0], value[1]]);
val2.push([value[0], value[2]]);

As per Pal's comment - changed it to this: 根据Pal的评论-将其更改为:

val1.push([value[0], value[1]]);
val2.push([value[0], value[2]]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM