Dynamically modifying the Chart layout options - Javascript highcharts

Javascript examples for highcharts:Chart Option

Description

Dynamically modifying the Chart layout options

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">
$(function () {/*from w  w  w  .j  ava2s  . c o  m*/
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'area',
                marginTop: 200
            },
            title: {
                text: 'Chart title'
            },
            xAxis: {
                labels: {
                    formatter: function() {
                        return this.value; // clean, unformatted number for year
                    }
                }
            },
            yAxis: {
                title: {
                    text: 'Nuclear weapon states'
                },
                labels: {
                    formatter: function() {
                        return this.value / 1000 +'k';
                    }
                }
            },
            plotOptions: {
                area: {
                    pointStart: 1940,
                    marker: {
                        enabled: false,
                        symbol: 'circle',
                        radius: 2,
                        states: {
                            hover: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series: [{
                name: 'F',
                data: [6 , 11, 32, 110, 235, 369, 640, 1005, 1436 ]
            }, {
                name: 'C',
                data: [5, 25, 50, 120, 150, 200, 426, 660, 869, 1060]
            }]
        });
    });
    var btn = $('#btn');
    btn.click(function(){
        chart.optionsMarginTop += 20;
        chart.isDirtyBox = true;
        chart.redraw();
    });
});

      </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="min-width: 400px; height: 400px; margin: 0 auto"></div> 
      <button id="btn">Trigger</button>  
   </body>
</html>

Related Tutorials