Warmest Wishes
Friday, December 21st, 2007For A Safe and Happy Holidays with Loved Ones
send me a note:
civy at instantcognition.com
![]()
Except where otherwise noted, this site is licensed under a Creative Commons Attribution 2.5 License
For A Safe and Happy Holidays with Loved Ones
Ok, so about ten days ago I challenged my readers to solve the following charting problems with the Google API - Bullet Chart, Sparkline and Square Pie. I provided a sample bullet chart but asked if anyone could improve upon it. Unfortunately, only one brave soul, Jeff Donnici, took up the challenge and provided two solutions for Sparklines.
I am inviting Jeff to write his own discourse on how to create sparklines with the Google API, so Jeff, please email me (my email is at the bottom of the right-hand nav) with your description of how to create the sparklines.
First, let’s cover some basics of the API.
The API is pretty simple, it’s just a URL with a bunch of query parameters attached to define the chart and its elements. It can also be a bit annoying when you’re encoding the data sets and their associated information. My guess would be that to really get the power out of the API you would want some sort of programmatic interface to it as building the chart request ‘by hand’ can be laborious.
So, components that are used in these examples:
For me, let’s start with the Bullet Chart. The stumbling blocks here are that
If you remember the Excel example of the Bullet chart, you will recall that we have 3 data series (top, middle, bottom) each with 4 data points to create the basic visualization of the Bullet chart. We then combine into that chart a scatter plot to create the target line. Well this API doesn’t support coloring for a single data point (which is required in the Excel solution) so what does Google offer as a replacement? Well, with the background fill, we can go a linear stripe that will take up some percentage of the chart space - ok, I think I can work with that:
But first things first. Let’s define the chart type:
http://chart.apis.google.com/chart?cht=bhs
Next, let’s set the chart size
http://chart.apis.google.com/chart?cht=bhs&chs=250×40
While we’re at it, lets go ahead and set the bar width (or height if you prefer)
http://chart.apis.google.com/chart?cht=bhs&chs=250×40&chbh=10,25
Ok, for the last of the easy bits, let’s go ahead and set the Chart title
http://chart.apis.google.com/chart?cht=bhs&chs=250×40&chbh=10,25&chtt=Homepage+Retention+Rate:+90%
On to the data. As noted above, there are 3 options for encoding data - simple, text, and extended. I haven’t really figured out why you would use simple because it’s basically a substitution scheme that feels more annoying than anything. However, in this example we are using text encoding because it allows us to use regular numbers with up to 1/10th precision.
http://chart.apis.google.com/chart?cht=bhs&chs=250×40&chbh=10,25&chtt=Homepage+Retention+Rate:+90%&chd=t:90.0
The above gives us a basic bar chart:
Now we need to add the elements that will make this look like a Bullet chart and we’re going to get it all done with chart fill!
http://chart.apis.google.com/chart?cht=bhs&chs=250×40&chbh=10,25&chtt=Homepage+Retention+Rate:+90%&chd=t:90.0&chf=c,ls,0,000000,0.50,cccccc,0.25,000000,0.005,efefef,0.245
chf (chart fill) takes the following arguments:
If you look at the URL snippet above in bold, you will see that we have defined
That’s it, now we have a functioning bullet chart
I sure wish that I could remove the axes lines, and add data labels to the bar and target line, but oh well.
Ok, I need to take a break as this is quite a long post. In part 2, we will walk through the pie chart solution (which is not that great),
I’m not quite sure how long I’ve been ignoring the Google Chart API but I saw it in a post the other day which reminded me, or at least gave me the inkling, that I had seen some discussion of it before.
Well, that was several days ago and I finally had some time to play with it and in a couple of hours created the following bullet chart:
So here’s the challange
Using the Google Chart API of course.
Once you’ve created your solution, post a link to it here in the comments. For the solutions that we like best, I’ll ask the author to provide a description and instructions to be published here in a follow up post.
Update: 12/15/2007
Jeff Donnici sends us two sparkline examples.
Simple:
With Banded Background:
Update 12/19/2007
Well with only Jeff taking up the challenge after 10 days, here’s the final solution: a so-called square-pie chart. Of the 3 types this is the most poorly supported by the Google API mostly because on bar charts you cannot control the scale of the axes.
Update Feb 29, 2008
Geoff offers us this austere Bullet Chart solution:
And this slightly "dressed up" version: