Google chart redraw/scale on window resize

前端 未结 9 1326
甜味超标
甜味超标 2020-12-07 19:50

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

9条回答
  •  长情又很酷
    2020-12-07 20:15

    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);
    });
    

提交回复
热议问题