use chart.addseries inside for loop - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

use chart.addseries inside for loop

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function () {/*  w  w  w  .j  a  va  2s.  com*/
    $('#container').highcharts({
        series: [{
            data: [29.9, 71.5]
        }]
    });
    // the button handler
    $('#button').click(function() {
        var chart = $('#container').highcharts();
        for(var i=0;i<4;i++){
            chart.addSeries({
                    data: [2,3,2]
            });
        }
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="height: 400px"></div> 
      <button id="button" class="autocompare">Add series</button>  
   </body>
</html>

Related Tutorials