Using Google Chart API in your website

Wednesday, May 6, 2009 2:44
Posted in category Api, PHP, Tutorial

Charts are useful and more informative way of representing data in a website. There are many commercial and opensource components and libraries available to implement charts in a website. Most of them are flash based and very attractive. There may be cases where you don’t want or can’t use flash based charts. So what are the alternatives? Write your own library using gd or any other image manipulation library or Use Google Chart API. Yes, google chart api is here to rescue you from all the tedious coding you will do to create your own library.

Google Chart API is simple and easy to implement and produces nifty chart in your website with the data you supplied to the API. The API generates a PNG-format image in response to a url. The API generates different kinds of Charts like bar, line, pie, 3D pie and that too in different color and sizes. isn’t that cool?

As already mentioned the google chart API is simple and easy to implement. (Read more about the chart API at http://code.google.com/apis/chart/) You just need to form a url in following format and send it to google.

http://chart.apis.google.com/chart? & &

e.g. http://chart.apis.google.com/chart?chs=350x150&chd=t:70,30&cht=p3&chl=Joomla|Drupal

Yes generating chart is that simple. Just copy the above example and see for yourself. Now let me explain the chart parameters.

http://chart.apis.google.com/chart? is the Chart API’s location.
& separates parameters.
chs=350x150 is the chart’s size in pixels.
chd=t:70,30 is the chart’s data.
cht=p3 is the chart’s type.
chl=Joomla|Drupal is the chart’s label.

You must at least provide chs, chd, cht parameters to the API. Now let us discuss some variations of  parameters

To know more about the Google Chart API, refer to google code at http://code.google.com/apis/chart/. The API docs provides all the information on how to use the Chart API in your website.

Happy Reading!

VN:F [1.8.3_1051]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.3_1051]
Rating: +1 (from 1 vote)
Using Google Chart API in your website10.0101
http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/digg_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/reddit_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/stumbleupon_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/delicious_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/blogmarks_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/google_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/myspace_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/facebook_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/yahoobuzz_32.png http://www.sanjeevshrestha.com.np/wp-content/plugins/sociofluid/images/twitter_32.png
You can leave a response, or trackback from your own site.

Leave a Reply