Sunday, February 10, 2008

Web charting? Piece of cake

You are still trying to figure out how to build charts with php? It's so last week..
Today, sniffing around, i got on the http://code.google.com, and discovered Google Chart API, which caught my attention from the start.
What google offers is a simple way to build charts, just with a request. Best example:The request behind this chart is: http://chart.apis.google.com/chart?chs=300x200&chd=s:MiMImia&
cht=lc&chxt=x,y&chxl=0:|1|2|3|4|5|1:||50+Kb

Now an example of access statistics, that is customized for our site:
So it has the same color as we use, and it has some nice bars (the white margins are not part of the chart, just can't figure out how to remove them:).
Let's dissect it and see how it's build:
http://chart.apis.google.com/chart? - the base request
chs=300x200 - chart image size
&chf=bg,s,CCDDBB - background color, in our case same as the blog.
&chd=s:MiMImia - this is the chart values, each character encodes a value from 0 to 61. There are more options.
&cht=bvg&chbh=20 - the type of chart (vertical bars) and their width
&chxt=x,y - axes
&chxl=0:|1|2|3|4|5|6|7|1:||50+Users|100+Users - the notations on the axis.

It looks pretty simple, doesn't it?
This is just a very basic example. You can chose from different chart types, coloring, sizes, etc. Perfect for small projects when some basic charting is needed.
But (there is always a but), you are limited by the URL length (if you are curios to know what is the maximum URL length: http://www.boutell.com/newfaq/misc/urllength.html), thou you will be able to show statistics for about 100 of your users for sure..

0 Comments:

Post a Comment

<< Home