Google Chart Builder

For Groovy and Grails

UPDATE: Due to a conflict in Grails with the set closure, it has been renamed to dataSet. The examples have been updated as well as the source code and tests.

A little while ago Google released a their Chart API into the wild. It’s basically allows a client to call a RESTful url and get a PNG image back of the chart. Very cool stuff. After playing with it for a little bit I quickly realized that this RESTful approach was both very powerful and very annoying. I primarily do web development and if I’m creating a chart I want it to be on the fly and dynamic. Injecting data and labels into a potentially long url was not my idea of a good time.

To see examples of these charts (Download the source code) and run the test suite under the ‘test’ folder. The following tests will have examples on how to use the Google Chart Builder and will also generate HTML files (in a folder named GoogleCharts under root)that contain the URL strings.

PieChartTest.groovy

BarChartTest.groovy

ScatterPlotTest.groovy

VennDiagramTest.groovy

LineChartTest.groovy

These

Documentation on the keywords that are used in the Google Chart Builder can be found in the ‘docs’ folder or here.

As you can see the Google Charts API allows you do generate some pretty complicated charts. However because of the RESTful nature of these charts the URLs can get out of hand very fast. My intention is to ease the pain in using this useful API.