python-coder
python-coder

Reputation: 2148

Pass data in highcharts

i want to pass data in Combination highCharts. It has a pie and a spline. I'm successfully able to pass data to pie but I'm unable to pass data to the spline. where I;m going wrong?

Here is my code.

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

Here is my jsFiddle

Upvotes: 2

Views: 1893

Answers (1)

Strikers
Strikers

Reputation: 4776

here you are passing the entire spline_data as one data set while it represents 2 splines.

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

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

I've updated your fiddle at http://jsfiddle.net/5qhx3/1/

Hope this will help you

Upvotes: 3

Related Questions