检索具有多个系列的Highcharts的JSON数据? [英] Retrieving JSON data for Highcharts with multiple series?

查看:103
本文介绍了检索具有多个系列的Highcharts的JSON数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究大量的例子,但我似乎无法让我的代码将数据提取出来。

我有一个php文件,它提供了以下内容:(date,value1,value2)

  [
[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]
]

然后我有以下代码:

 <!DOCTYPE html> 
< head>
< script src =js / jquery-1.10.2.min.js>< / script>
< script src =js / highcharts.jstype =text / javascript>< / script>
< script>
var chart;
$(document).ready(function(){
var options = {
chart:{
renderTo:'container',
type:'line',
},
title:{
},
xAxis:{
类型:'datetime'
},
yAxis:{
$,
,$ {
名称:'val1',
data:[]
},{
名称:'val2',
data:[]
}]
};
$ .getJSON('data_day.php',函数(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>

我试图用萤火虫查看出错的地方。如果我把

  console.log(key,value)

下的$ .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]

/ p>

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

  options.series [0] .data = val1; 

更新:将其更改为此并正在运行。

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


解决方案

根据Pal的评论 - 将其更改为:

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


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)

[
["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:

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:

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

这篇关于检索具有多个系列的Highcharts的JSON数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆