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 .
Posted in technology, visualisation
