Posted by: decster | January 7, 2008

A first look at Google Chart

The Google Chart API has been around for a few months now but I’ve only gotten around to having a play with it this evening. The API offers an easy way to generate simple graphs for embedding in a web page. To use the API you construct a URL with parameters specifying how the graph will appear and including the encoded chart data and in return it then presents you with a PNG representation of your chart. Essentially what you are doing is simply hotlinking to the picture of the chart which is hosted by Google. Of course there’s nothing to stop you saving the image and uploading it to your website later on but for ad hoc generation of charts, Google are onto a good thing. Enough with the prattle, lets take a look at how it works.

To generate a chart one of course needs data. Unbeknownst to many, I take a keen interest in the construction of new wind farms in my native Ireland. This may have something to do with the plans to construct one of the world’s largest offshore wind farms near where I grew up or maybe it’s simply because I like windmills. Anyway this data from Sustainable Energy Ireland on the construction of wind farms in Ireland over the past few years affords me the opportunity to graph some meaningful data.

Adding up the amount of megawattage constructed every year in Ireland between 2000 and 2006 provides the following dataset:

2000 2001 2002 2003 2004 2005 2006
46.67 8.4 12.575 74.4 135.15 152.25 246.5

 

In order to use the API you need to encode the above data into a more compressed version using one of a choice of encoding techniques. As I’m using a small dataset, I’m using the simplest encoding technique. Google provide some sample Javascript so after a few minutes effort I’ve encoded my dataset as JCCPbfy. In addition to the data I also need to include the labels for the X and Y-axes, dimensions of the image, the encoding technique used and a few other parameters which are well documented by Google. So what I’ve ended up with is a URL that looks like the following (I’ve highlighted the bits I’ve had to edit in bold):

http://chart.apis.google.com/chart?chs=400×250&chd=s:JCCPbfy&cht=lc&
chxt=x,y&&chxl=0:|2000|2001|2002|2003|2004|2005|2006|1:||300+MW

And that’s it. I then simply take that URL and either wrap it in an <img> tag or, in this case, just point WordPress at it.

It’s nice to see that the number of wind farms completed each year in Ireland is on the increase but lets say I want a bar chart instead. Well that’s easy-peasy, I just change the cht parameter to say bvs and that’s it, I have a bar chart.

And who doesn’t like pie?

I’m only scratching the surface here and there are a bunch of other features like specifying colours, handling multiple datasets and so on. Sure there are limitations, like you can’t have more than 4,096 values in your dataset, but I suspect Google are onto another hit here. People like to talk about Software as a Service but I think what we are looking at here is another example of Components as a Service. Look at the ubiquity of Google Maps and you can see how Google Charts could become increasingly prevalent.

While I can’t see large enterprises ever using Google Charts in a big way, their mindsets aren’t designed to send data beyond their walls, I think there are important take-aways. For example, why not provide something equivalent to Google Charts for your applications? Why have disparate development teams each developing graphing components when those same graphs could be provided as part of a centralised service? In some enterprises the idea of separate software components already exists for things like search or authentication. My bet is that it won’t be too long before we see graphing offered in a similar way.

Plenty to chew over and something I’ll return to in the future .

Responses

Pretty neat stuff…

One more step on the road to merging online/offline documents (ie the ‘wikification’ of ppt, doc, xls etc…)?

Will try to remember to think of this next time I have something I want to show graphically on my site.

Also I always wondered why large companies didn’t embrace componentization in their software / gui designs long long ago…something I would have liked to have championed if Digital Markets had been allowed to continue… I suspect it has to do with the same old feudal jealousies that hamstring so many opportunities for collaboration and cooperation in large organizations…

Whenever I think of software components as a service, LEGO always comes to mind. It’s simple, standardised, easily interchangeable and, most importantly, universally accessible. Sadly it is a concept that large companies don’t readily get. It’s almost as if their pondering size acts against them, allowing this feudal system to come about. Somewhere between the graduate hire and the CIO, the blue chips forget why the principle behind LEGO is such a powerful one.

Nice article, way over my head but im only starting to pull apart its API. Cheers for the info though.

Nice article,its good to read this, keep it up!

[...] Chart and sparklines Following on from my earlier post on the Google Chart API, I have been playing around with the API a bit more. This time I’ve [...]

Leave a response

Your response:

Categories