update series using button - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

update series using button

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://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script> 
      <style id="compiled-css" type="text/css">

#container {/*from   w  w w .  j a v  a  2s. co m*/
   min-width: 310px;
   max-width: 800px;
   height: 400px;
   margin: 0 auto
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container"></div> 
      <button id="modify"> change series </button> 
      <script type="text/javascript">
var series = [{
    data: [1, 2, 3, 4]
}, {
    data: [4, 3, 2, 1]
}];
var chart = Highcharts.chart('container', {
    series: series
});
$("#modify").on('click', function() {
    series = [{
        data: [Math.random() * 4, Math.random() * 4, Math.random() * 4, Math.random() * 4]
    }, {
        data: [Math.random() * 4, Math.random() * 4, Math.random() * 4, Math.random() * 4]
    }]
    chart.update({
        series: series
    });
});

      </script>  
   </body>
</html>

Related Tutorials