by Rick Glos
30. January 2008 21:57
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.
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:
| Date |
Mileage |
| 2008.01.15 |
19 |
| 2008.01.16 |
30 |
| 2008.01.22 |
25 |
| 2008.01.24 |
25 |
| 2008.01.28 |
23 |
| 2008.01.30 |
23 |
Using a pivot table we can quickly summarize this data:
| Week Number |
Mileage |
| Week 1 |
0 |
| Week 2 |
0 |
| Week 3 |
49 |
| Week 4 |
50 |
| Week 5 |
48 |
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=300x200 |
create a chart 300 pixels wide by 200 pixels tall |
| &chd=t:0,0,49,50,48 |
chart data for the 5 weeks |
| &cht=lc |
line chart (vs pie, bar, venn, and scatter) |
| &chxt=x,y,x,x |
multiple chart axis |
| &chxl= |
labels |
| 0:|Week+1|Week+2|Week+3|Week+4|Week+5| |
labels for the 1st x axis |
| 1:||25|50|75|100 |
labels for the only y axis |
| 2:|Jan| |
label for the 2nd x axis |
| 3:|2008| |
label for the 3rd x axis |
| &chtt=2008+Bicycle+Mileage |
chart title |
| &chm=B,FFE4BB,0,0,0 |
chart fill color |
| &chxp=1,0,25,50,75,100 |
y 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.
Later.
c69fe360-38af-43cb-ac94-1c0ac62800fb|0|.0
Tags: programming
by Rick Glos
29. January 2008 05:46
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.
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.
Later.
e7630360-9312-4d5b-b7af-38e8d922667a|0|.0
Tags: