Mar
12
2008

testing out the google chart api

Google recently released a tool that allows users to quickly create impressively clean dynamic charts and graphs. I played around with it a bit this morning and found it super-easy to use. For example, check out these charts of last night’s Mississippi primary results:

[Chart: Mississippi Democratic primary results][Chart: Mississippi Republican primary results]

These pie-charts were easy to create and manipulate, just by adjusting some variables in the image URL string:

http://chart.apis.google.com/chart?cht=p&chd=t:61,37,1,1&chs=250x75&chl=Obama+%2861%25%29|
Clinton+%2837%25%29|Edwards+%281%25%29|Other+%281%25%29&chco=4c5c79

Breaking down the URL:

  • cht=p - Type of chart (in this case, a pie chart)
  • &chd=t:61,37,1,1 - Chart data, comma delimited
  • &chs=250x75 - Chart dimensions (width by height)
  • &chl=Obama+%2861%25%29|Clinton+%2837%25%29|Edwards+%281%25%29|
    Other+%281%25%29
    - Labels. I didn’t find an option to have the API automatically append the chart data / percentages to the end of each label, so I had to add them in manually. (“+” = space, “%28” = “(“, %25 = “%”, “%29” = “)”)
  • &chco=4c5c79 - The base color, in hex format. If you only specify one color but there are multiple slices, the API will start at the color you’ve specified and use progressively lighter shades of that color for the other slices.

Post a comment

As a spam-control measure, your comment may require my approval before it will appear on the entry. Thanks for waiting. To avoid the moderation delay, consider filling in your e-mail address. It won't appear on the site, but I use it to whitelist frequent commenters so their comments appear automatically.


The following HTML tags are permitted (if you want to use them):
p, br, a href, b, strong, u, i, em, ol, ul, li, cite, blockquote

TrackBack

TrackBack URL for this entry: http://www.morethanthis.net/mtadmin/mt-tb.cgi/4176