Fixing styling incompatibility with Google Charts and Twitter Bootstrap
Ran into a vexing issue this week when we upgraded to using Twitter Bootstrap. Some of our analytics graphs using Google Charts were suddenly broken in IE 7/8/9. Instead of the expected 100px wide bar graphs, they were just a few pixels wide.
Normally Google Charts produces the following DOM for their bar graphs.
It turns out that the issue is with Bootstrap’s CSS for responsive images, and in particular the img { width: auto; }
declaration. It causes older versions if IE to ignore height
and width
attributes that are set directly on the DOM element. This issue has come up before in other contexts. Removing the offending CSS solves the issue, but I wanted to stick with vanilla Bootstrap so we could cleanly upgrade to new vesions. Likewise, you probably don’t want to edit the Google Charts javascript.
Instead, you can layer in some additional javascript, fired on the Google Charts onReady
event, to add inline width
declarations into the style
attribute for the images. While IE 7/8/9 ignore width attributes when combined with img { width: auto; }
, it does respect style
attributes.