Grails Google Chart API Plugin

14 December, 2007

Since it was announced several days ago, I’ve been messing around with Google Chart API and Grails plugins.

Here’s an example of the code to produce a pie chart:

    <% 
        def labels = [’First’,’Second’,’Third’] 
        def colors = [’FF0000’,’00ff00’,’0000ff’] 
        def values = [35,45,10] 
    %> 
       

It produces the image tag:

<img src="http://chart.apis.google.com/chart?chs=400x200&chd=s:v9O&chl=First|Second|Third
      &chco=FF0000,00ff00,0000ff&chf=bg,s,efefef&chtt=Sample Pie Chart&cht=p3" />

That code produces the following pie chart:

Sample Pie Chart Generated by Google Chart API

 

Download: grails-google-chart-0.1.zip Now available in the Grails Plugin Repository ...install with:

 

grails install-plugin google-chart

 

As with the social bookmarks plugin, there are more extensive examples in the plugin itself. Run it with grails run-app to see them. Some of the advanced features aren’t implemented yet like item markers and the like but you are able to use any of the three types of encoding, multiple datasets, all chart types and axis labeling.

Because of the 1,000 call threshold imposed by Google, unless you want to risk your charts not showing up, it wouldn’t be a good idea to use this on a high traffic site since it does a straight call. The next evolution will probably be some sort of caching mechanism based on the dataset, other attributes, or something.

Edit: It’s actually 50,000 calls per day. 

Let me know what y’all think..

 

Share/Save/Bookmark

Related Posts:
Two weeks with the ZK framework
Handling Legacy URLs
A couple days with Grails
And then there were three

Comments

  1. Glen said:

    That looks fantastic! Can you do alpha blending on the background to produce transparency? Great Stuff!
  2. JW said:

    Not yet. I vaguely remember seeing someone do that in Python and made a mental note to look into it after I have all the features at least 90% implemented.
  3. dbf said:

    I don't think the 1000 call limit is true any more. Just went to Google Chart website and found this: Use of the Google Chart API is subject to a query limit of 50,000 queries per user per day. If you go over this 24-hour limit, the Chart API may stop working for you temporarily. If you continue to exceed this limit, your access to the Chart API may be blocked.
  4. Twistleton said:

    Thank you very much for very useful grails plugin. I use it now in my application ...

Leave a comment