Javascript 在海图中传递数据

Javascript 在海图中传递数据,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我想在组合图表中传递数据。它有一个饼和一个样条。我能够成功地将数据传递到饼图,但无法将数据传递到样条曲线。我在那里;我做错了 series: [{ type: 'spline', data: spline_data[0].data, showInLegend: true, },{ type: 's

我想在组合图表中传递数据。它有一个饼和一个样条。我能够成功地将数据传递到饼图,但无法将数据传递到样条曲线。我在那里;我做错了

              series: [{
                  type: 'spline',
                  data: spline_data[0].data,
                  showInLegend: true,

              },{
                  type: 'spline',
                  data: spline_data[1].data,
                  showInLegend: true,
              }
这是我的代码。

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script src="http://code.highcharts.com/highcharts.js"></script>
        <script src="http://code.highcharts.com/modules/exporting.js"></script>
        <script type="text/javascript">

       var spline_data = [{  // this value is to be passed downwards.
                'name': 'Bangalore',
                            'data': [
                                [1383741000000, 1608.3000000000002],   //[time in secs since 1970, value to be plotted against the time.]
                                [1383741900000, 1611.9999999999973],
                                [1383742800000, 1612.299999999997]
                            ]

                        }, {
                'name': 'New Delhi',
                            'data': [
                                [1383741000000, 54.2],
                                [1383741900000, 54.300000000000004],
                                [1383742800000, 54.300000000000004]
                            ]

                        }];

      var pie_data = [
                ['Firefox',   45.0],
                ['IE',       26.8],
                ['Chrome',   12.8],
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]

    $(function () {
        $("#container").highcharts({
          chart: {
            height : 300,
            backgroundColor : '#fafafa',
          },
          title: {
              text: 'Energy Chart'
          },

          xAxis: {
              type: 'datetime',
              dateTimeLabelFormats: { // don't display the dummy year
                  month: '%e. %b',
                  year: '%b'
              }
          },

          tooltip: {
              formatter: function() {
                  var s;
                      s = this.y + 'kWh';
                  return s;
              }
          },

          series: [{
              type: 'spline',
              data: spline_data,
              showInLegend: true,

          }, {
              type: 'pie',
              data: pie_data,
              center: [90, 20],
              size: 100,
              cursor: 'pointer',
              showInLegend: true,
              dataLabels: {
                  enabled: false,
              },
point :{
      events:{
        click : function(){
          level_id = level_id + 1;
          var pie_selected_location = this.name;
          $.ajax({
            dataType: "json",
             type : 'POST',
            url : '/dashboard/',
            data : {'pie_selected_location': pie_selected_location, 'level_id' : level_id},
            success: function(result){
              comparison_chart(result,level_id);
            }
          });
        }
      }
    },
         }]
        });
          });
        </script>

    </head>
    <body>
        <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
    </body>
</html>
              series: [{
                  type: 'spline',
                  data: spline_data[0].data,
                  showInLegend: true,

              },{
                  type: 'spline',
                  data: spline_data[1].data,
                  showInLegend: true,
              }

var spline_data=[{//此值向下传递。
“姓名”:“班加罗尔”,
“数据”:[
[13837410000001608.30000000000002],/[自1970年以来以秒为单位的时间,根据时间绘制的值。]
[1383741900000, 1611.9999999999973],
[1383742800000, 1612.299999999997]
]
}, {
“名称”:“新德里”,
“数据”:[
[1383741000000, 54.2],
[1383741900000, 54.300000000000004],
[1383742800000, 54.300000000000004]
]
}];
变量pie_数据=[
['Firefox',45.0],
[IE',26.8],
[Chrome',12.8],
[Safari',8.5],
[Opera',6.2],
[“其他”,0.7]
]
$(函数(){
$(“#容器”)。高图({
图表:{
身高:300,
背景颜色:“#fafafa”,
},
标题:{
文字:“能量图”
},
xAxis:{
键入:“日期时间”,
dateTimeLabelFormats:{//不显示虚拟年份
月份:'%e.%b',
年份:'%b'
}
},
工具提示:{
格式化程序:函数(){
var s;
s=这个.y+‘kWh’;
返回s;
}
},
系列:[{
类型:“样条线”,
数据:样条曲线数据,
showInLegend:是的,
}, {
键入“pie”,
数据:饼图数据,
中间:[90,20],
尺码:100,
光标:“指针”,
showInLegend:是的,
数据标签:{
启用:false,
},
要点:{
活动:{
单击:函数(){
级别id=级别id+1;
var pie_selected_location=this.name;
$.ajax({
数据类型:“json”,
键入:“POST”,
url:“/dashboard/”,
数据:{'pie_selected_location':pie_selected_location,'level_id':level_id},
成功:功能(结果){
比较图表(结果、级别id);
}
});
}
}
},
}]
});
});

这是我的

这里,您将整个样条曲线数据作为一个数据集传递,而它代表2条样条曲线

              series: [{
                  type: 'spline',
                  data: spline_data[0].data,
                  showInLegend: true,

              },{
                  type: 'spline',
                  data: spline_data[1].data,
                  showInLegend: true,
              }
我已经更新了你的小提琴

              series: [{
                  type: 'spline',
                  data: spline_data[0].data,
                  showInLegend: true,

              },{
                  type: 'spline',
                  data: spline_data[1].data,
                  showInLegend: true,
              }

希望这能帮助你

你好@罢工者-这只是一个示例。如果样条曲线_数据中有9-10个数据条目呢?然后呢?我不能再这样下去了?有什么通用的解决方案吗?在这里,我所做的是首先构建整个数据,然后将其传递给系列是的,我只想要这样的东西。谢谢让我试一试。@strikers添加了
name:spline_data[0]。name,
@RubenKazumov:yes,而不是访问每个参数,他只需先构建整个对象,然后将其分配给序列。这实际上会有所帮助
              series: [{
                  type: 'spline',
                  data: spline_data[0].data,
                  showInLegend: true,

              },{
                  type: 'spline',
                  data: spline_data[1].data,
                  showInLegend: true,
              }