by Flo Preynat

A quick blog post on how to make Google Charts play nicely in responsive mode. Nothing close to rocket science but still useful.

For those who don’t know, Google Charts is a visualization tool, a gallery of interactive charts and data tools that you can integrate into your website. You provide data through php, json and Google Charts display it nicely for you.

As I’m using those in a project involving responsive web design and encountered a minor issue, I thought I would post a wee something for you’s.

Issue

By default, the charts come in the form of fixed width element which you can easily tweak to adapt to the now-famous ‘width:100%’ format. However the charts will only appear in that format when the page is loaded. They won’t dynamically resize when the browser window width is changed.

This is what the charts look like when initially loaded:

google-charts-responsive1

This what they look when resizing the browser:

google-charts-responsive2

This is what they look when reloading the page:

google-charts-responsive3

Solution

You will need to add a little jquery to get that to work as expected.

$(window).resize(function(){
  drawChart1();
  drawChart2();
});

There’s obviously a codepen for this.

So Long.

My name is Flo Preynat and I am the freelance webdesigner and developer behind shoogle designs. I live in France and specialize in responsive web design. Give me a shoogle or get in touch with me on twitter.

Follow @shoogledesigns

Most Recent Posts

Special Recent Posts

Sip: a color picker refreshingly simple indeed

Sip: a color picker refreshingly simple indeed

July 10th, 2014

I've just discovered Sip, a color picker app for Mac users. "Just discovered" since it's been around[...]

Perch – the CMS that does not pollute your web design workflow

Perch - the CMS that does not pollute your web design workflow

July 7th, 2014

I have recently finished a project based on Perch, the clever 'little' CMS created by edgeofmyseat.c[...]

Responsive video code snippet

Responsive video code snippet

June 29th, 2014

More of a reminder than a pure detailed blogpost, this code snippet will be my go-to resource when I[...]

Project Naphta: a nifty extension to play with text embedded in images

Project Naphta: a nifty extension to play with text embedded in images

June 9th, 2014

We've all been there. You want to select a good chunk of text on a website, only to realise you can'[...]

Free photos for your web design projects

Free photos for your web design projects

June 4th, 2014

Nothing beats using a real professional photographer when working on a cool project. You can be the[...]

Comments

  1. MHC says:

    Hey gracias, fue una gran idea !!! para el responsive !

  2. Matthew Holland says:

    Flo,

    I tried your example and it KNOCKED MY SOCKS OFF!! I’ve been struggling with getting google charts to become responsive on my sight and thanks to you it actually works now. Can’t thank you enough.

    Cheers mate,
    -Matt

  3. Helen says:

    Hey Flo,

    Thank you very much for sharing it with us! Top 10!

    =)
    Helen

    Reply
  4. Marcio says:

    Don’t work with google table chart :/
    See my example: http://i.imgur.com/1wtkPaG.png?1

    Reply
  5. Igor Iof says:

    Hey Flo,
    You are the best!!!
    Just 3 lines of the code solved my problem!!!
    respect, Man !

    Reply