Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google visualization chart, size in percentage

How do you set the size of a google chart in percentage : I have this in the html:

<div id="chart_div" width="90%" height="20%"></div> 

and no width nor height in the options in the js.

But the chart size doesn't adapt to the viewport.

like image 338
Louis Avatar asked May 11 '14 13:05

Louis


2 Answers

First, use styles to set your dimensions, not attributes:

<div id="chart_div" style="width: 90%; height: 20%;"></div> 

The chart will draw to the size of the div by default, but the charts are not responsive. You have to hook a "resize" event handler to the window (or other element if you are resizing within a window) that redraws the chart:

function resizeChart () {     chart.draw(data, options); } if (document.addEventListener) {     window.addEventListener('resize', resizeChart); } else if (document.attachEvent) {     window.attachEvent('onresize', resizeChart); } else {     window.resize = resizeChart; } 
like image 53
asgallant Avatar answered Sep 19 '22 13:09

asgallant


By multiplying with appropriate factor to $(window).width() or $(window).height() in the chart options

var options = {         width: $(window).width(),         height: $(window).height()*0.75 }; 
like image 24
nole Avatar answered Sep 18 '22 13:09

nole