Treat option as click event on select drop-down list - Javascript highcharts

Javascript examples for highcharts:Chart Event

Description

Treat option as click event on select drop-down list

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <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" src="http://highcharts.com/js/testing.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/*from   w w w.ja v  a2  s.  c  om*/
var options = {
    chart: {
        renderTo: 'container',
        defaultSeriesType: 'spline'
    },
    series: [{name: 'A', data: [1,2,3,2,1]}]
};
var chart = new Highcharts.Chart(options);
$("#list").on('change', function(){
    //alert('f')
    var selVal = $("#list").val();
    if(selVal == "A" || selVal == '')
    {
        options.series = [{name: 'A', data: [1,2,3,2,1]}]
    }
    else if(selVal == "B")
    {
        options.series = [{name: 'B', data: [3,2,1,2,3]}]
    }
    else if(selVal == "C")
    {
        options.series = [{name: 'C', data: [5,4,8,7,6]}]
    }
    else
    {
        options.series = [{name: 'D', data: [4,7,9,6,2]}]
    }
    var chart = new Highcharts.Chart(options);
});
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <select id="list"> 
         <option value="A">Data Set A</option> 
         <option value="B">Data Set B</option> 
         <option value="C">Data Set C</option> 
         <option value="D">Data Set D</option> 
      </select> 
      <button id="change">Refresh Table</button> 
      <div id="container" style="height: 400px"></div>  
   </body>
</html>

Related Tutorials