Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google chart redraw/scale on window resize

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

like image 916
thecodeparadox Avatar asked Jan 21 '12 04:01

thecodeparadox


People also ask

How do I redraw a chart in Google?

To redraw or scale Google chart on window resize with JavaScript, we can redraw the chart when we resize the screen. const resize = () => { const chart = new google. visualization. LineChart( document.

How do you change the width of a Google chart?

Specify Chart Size One very common option to set is the chart height and width. You can specify the chart size in two places: in the HTML of the container <div> element, or in the chart options. If you specify the size in both locations, the chart will generally defer to the size specified in the HTML.


1 Answers

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); }); 
like image 50
Hemerson Varela Avatar answered Sep 27 '22 21:09

Hemerson Varela