Implementing google charts with 100% width !!!

23,844 views
Skip to first unread message

shub

unread,
Mar 26, 2012, 2:03:40 AM3/26/12
to google-visua...@googlegroups.com
Hello,

I want to know if we can create google charts with 100% width...
I tried to give the width as 100%, but they doesn't seem to work...Does anyone know how to achieve this.. ?

asgallant

unread,
Mar 26, 2012, 1:29:54 PM3/26/12
to google-visua...@googlegroups.com
I ran a test case setting the 'width' option to '100%' and it seems to work fine (at least, it does in Chrome).

Vincent Wansink

unread,
Feb 25, 2016, 2:17:47 PM2/25/16
to Google Visualization API
The google api does not provide a mechanism for this because it has a hard coded "px" which is appended to the width value.  Inserting a % mark will choke the javascript engine.

However, there is an easy solution.  Calculate the width of the parent element and set the chart width to that.

With jQuery for example:

var chartwidth = $('#chartparent').width();

var options = {
    width
: chartwidth,
   
...
    chartArea
: {width:chartwidth,left:20,top:20,height:110}

};

Faraz Shaikh

unread,
Jun 25, 2016, 3:27:57 AM6/25/16
to Google Visualization API
Thank you so much Buddy..

Bhavani Shankar

unread,
Sep 19, 2019, 2:24:09 AM9/19/19
to Google Visualization API
Hey can we apply this in resize event also? we have a global function with data params.
In that we need to apply the chart Resize.window.resize (function (){ })
The option of redraw chart is made typical every time for inside function,.any alternative for this issue.??
Reply all
Reply to author
Forward
0 new messages