Update and set chart property in Javascript - Javascript highcharts

Javascript examples for highcharts:Chart Configuration

Description

Update and set chart property in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container" style="height: 400px; border: 1px solid grey;"></div> 
      <script type="text/javascript">
Highcharts.chart('container', {
  chart: {//from  ww w .  j  ava  2 s. c o  m
    type: 'bar',
    style: {
      fontFamily: "Montserrat"
    },
    events: {
       load: function() {
        var chart = this,
              xAxis = chart.xAxis[0],
            width;
        width = xAxis.labelGroup.getBBox().width;
        chart.update({
           chart: {
             margin: [50, 50, 100, width + 50]
          }
        }, true, false, false);
      }
    }
  },
  xAxis: {
    categories: ['Very very very very long january', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },
  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 12.2, 41.5, 22.4, 12.1]
  }]
});

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

Related Tutorials