Thursday, February 14, 2008

Sparklines with the Google Chart API

Sparklines are described in Edward Tufte's book Beautiful Evidence (2006) as “small, high resolution graphics embedded in a context of words, numbers, images”. In one of our projects we needed sparklines and one option was to use this open source package by Larry Ogrodnek. Just out of curiousity I was wondering how far we would come if we would use the Google Chart API. My final result looked promising ...

Sparkline with x/y axis

... but there was no way I could get rid of the gray x- and y-axis.

That was until I ran into this article where I saw sparklines created with the Google Charts API and without the x- and y-axis. How the hell did he do it?

Well ... it seems to be an undocumented feature also used by Google on their financial site. Instead of using cht=lc (chartype is line chart) you can use cht=lfi (charttype is financial line chart). And yes here is the final result:

Sparkline

Grab the code:

http://chart.apis.google.com/chart?chs=80x20&cht=lfi&chco=0077CC&&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=t:27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25 

No comments:

Post a Comment

Comment now »