javascript - 在 Highcharts 中传递数据

标签 javascript jquery highcharts

我想在组合 highCharts 中传递数据。它有一个饼图和一条样条线。我成功地将数据传递到饼图,但无法将数据传递到样条线。我哪里出错了?

这是我的代码。

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

这是我的 jsFiddle

最佳答案

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

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

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

我已经更新了你的 fiddle http://jsfiddle.net/5qhx3/1/

希望这对您有帮助

关于javascript - 在 Highcharts 中传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20041568/

相关文章:

javascript - AngularJS 分享功能

javascript - Node JS "Is not Defined"错误

javascript - 如何在 highcharts 的每个级别上使用不同图表的 drilldown up to level 3?

javascript - 如何更改 Highchart 工具提示字体系列

javascript - Vue 3 如何正确更新 Highcharts 中的数据?

javascript - onSet 函数不会在 div 上触发

javascript - 我可以自定义哪个属性控制事件的开始吗?

javascript - jQuery Accordion - 如何使用 URL 传递状态?

javascript - 如何在 Chart.JS 中将计算值附加到条形的末尾?

IE9 中的 jQuery 悬停错误