Google chart redraw/scale on window resize

thecodeparadox picture thecodeparadox · Jan 21, 2012 · Viewed 71.7k times · Source

How do I redraw/rescale a google linechart on window resize?

Answer

Hemerson Varela picture Hemerson Varela · Dec 4, 2013

To redraw only when the window resize is completed and avoid multiple triggers, I think is better create an event:

//create trigger to resizeEnd event     
$(window).resize(function() {
    if(this.resizeTO) clearTimeout(this.resizeTO);
    this.resizeTO = setTimeout(function() {
        $(this).trigger('resizeEnd');
    }, 500);
});

//redraw graph when window resize is completed  
$(window).on('resizeEnd', function() {
    drawChart(data);
});