responsive on first render - Javascript highcharts

Javascript examples for highcharts:Responsive Chart

Description

responsive on first render

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#container {// w  ww.java  2s  .  c  om
   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> 
      <script type="text/javascript">
Highcharts.chart('container', {
  chart: {
    events: {
      load: function() {
        var chart = this,
          legend = chart.legend,
          chartWidth = chart.chartWidth;
        if (chartWidth < 400) {
          legend.update({
            enabled: false
          });
        }
      }
    }
  },
  plotOptions: {
    series: {
      label: {
        connectorAllowed: false
      },
      pointStart: 2010
    }
  },
  series: [{
    name: 'Installation',
    data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
  }, {
    name: 'Manufacturing',
    data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
  }],
  responsive: {
    rules: [{
      condition: {
        maxWidth: 400
      },
      chartOptions: {
        legend: {
          enabled: false
        }
      }
    }]
  }
});

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

Related Tutorials