Rick Glos Life in Portland, Oregon.

Google Chart API

30. January 2008 12:57 by Rick Glos in

Google has introduced a way to dynamically create charts by using a url.  As an example, here's my bicycle mileage by week for the month of January.

2008 Bicycle Mileage

If you right click the image on the right you'll see that's it's not a static image by looking at the properties (right-click the image and select Properties).

What's that mean?  Well if you navigate to Google's homepage and check the properties of their image you'll see it links directly to a file called logo.gif, whereas the image above does not link to a file at all, it's generated each time the page is accessed.


It gets all the information needed to render the image from the garbage you see after the question mark: http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello|World.

To get an idea of how it works and what's possible I graphed my cycling mileage.

What I needed first was to aggregate the data.  If I look at the mileage log that I keep in Microsoft Excel it looks something like this:


Using a pivot table we can quickly summarize this data:

Week NumberMileage
Week 10
Week 20
Week 349
Week 450
Week 548

Now we need to put that into a format that the Google Chart API can handle.

Here's a breakdown of the long url needed to create the image above:

http://chart.apis.google.com/chart?this is the API endpoint
chs=300x200create a chart 300 pixels wide by 200 pixels tall
&chd=t:0,0,49,50,48chart data for the 5 weeks
&cht=lcline chart (vs pie, bar, venn, and scatter)
&chxt=x,y,x,xmultiple chart axis
0:|Week+1|Week+2|Week+3|Week+4|Week+5|labels for the 1st x axis
1:||25|50|75|100labels for the only y axis
2:|Jan|label for the 2nd x axis
3:|2008|label for the 3rd x axis
&chtt=2008+Bicycle+Mileagechart title
&chm=B,FFE4BB,0,0,0chart fill color
&chxp=1,0,25,50,75,100y axis label positions

It looks like alot of work and it was at first.  You could get better hacking this out over time but you'd definitely want a some kind of method that would start with the data and just emit the url.

Currently there's a limit of 50,000 queries per day per user.  It would take alot of hits to max that out, and this blog doesn't have that kind of traffic.  It is a good tool for creating an image of a chart.  They state that it was created to, "support rapid embedding of charts within our own applications".  I'm not sure how rapid this is compared to whipping it up in Excel and saving the image as a file for the average user.  A developer could get some mileage out of this but the 50,000 day limit would be something to consider.

You can find all the documentation for the API here.  As a proof of concept I may try and update the graph weekly or monthly and see how it goes.



28. January 2008 20:46 by Rick Glos in

As the time passes it's not like I don't have things to blog about.  It's that I'm too damn lazy to write.  I think about wanting to post about topic A, and then don't forget B, and then there's this story about C and then I think, this is too much work.

Perhaps it's just the short days, lack of sunshine.

When it gets really cold out here, from the wind blowing down the Columbia River Gorge, it blows away all the rain clouds.  Last week it was 19 degrees and sunshine and with an 1:15 - 1:30 on the bike I had to wear Ski Goggles to keep my eyes from freezing.  The Ski goggles plus the balaclava left me with no exposed skin and so the ride was very comfortable.  Only my toes were icicles.  I tried using both toe warmers and hand warmers for my feet and settled with the toe warmers being a better option as the hand warmers didn't work at all.  Heidi talked me into ordering some winter cycling shoes which should help my feet.

This week the temperature is right around freezing and we had some light snow accumulation.

Morning bicycle commute in Portland. OR

Even in winter it's still green.

Last week I wiped out on the ice and broke one of the brackets snaps off on the panniers.  Today I was able to maintain balance.  Although I almost lost it on the downward side of the northbound I-5 bridge when the rear started fishtailing.  Not so smart on two wheels.  Guess I should get off my lazy ass and put on tires that aren't slick road tires.  I keep expecting to turn the corner and the 45 degree rainy days.

Then again, maybe a good wipeout will make for a good post.