Highcharts - Responsive Resize

by Ayyappan Sakthivadivel

HTML

<script src="//code.highcharts.com/highcharts.js"></script>
<script src="//code.highcharts.com/modules/exporting.js"></script>
<div class="wrapper">
    <div id="container" style="width:100%;height:100%;"></div>
</div>

JavaScript

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
       },
        title: {
            text: 'Responsive Resize'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox', 45.0],
                ['IE',      26.8],
                ['Safari',  8.5],
                ['Opera',   6.2],
                ['Others',  0.7]
            ]
        }]
    });
    
    $(window).resize(function(){
        var chart = $('#container').highcharts();
        
        console.log('redraw');
        var w = $('#container').closest(".wrapper").width()
        // setsize will trigger the graph redraw 
        chart.setSize(       
            w,w * (3/4),false
        );
     });
    
});