Blog post -
Using Google Charts from rails
A week ago i got an interesting ticket - update the Newsdesk statistics charts for printing and sending via email. Although people here are quite satisfied whith the look and feel of our current solutions Fusion Charts, we feel that not being able to print the whole statistics page in one job is a huge drawback. Browsing through the different alternatives for graphic charting, once again I stumbled upon a free of charge, easy to use google service called Google Charts.
Google Charts seemed pretty straight forward and fairly easy to implement so it was an easy decision to go for it. My goal was to substitute the Fusion Charts with Google Charts in the event of printing or emailing the stats (we keep FC for online viewing since, after all, it provide a huge amount of fluff and motional joy for the end user).
I found no less than three different ruby wrappers for the Google Charts API:
- Googlecharts (gem)
- gchartrb (gem)
- google-charts-on-rails (rails plugin)
To save you the time, here is a quick comparison between the three:
gem install googlecharts
- it's possible to set a custom key with stuff that are not included in the wrapper(grids for example)
- nice and clean syntax with options-hash like arguments
- possible to specify ouput format such as file or image_tag
- not implemented grid, line_thickness, and ranges (to my knowledge). This
is fairly easy to implement by yourself using the custom option though.
gem install gchartrb
- block syntax is always nice
- easy handling of axises (above)
script/plugin install http://google-charts-on-rails.googlecode.com/svn/google_charts_on_rails/
Example: (i have none of my own)
- it's not nothing
- weird method_missing -like syntax
- poor doc
- much of Google Charts API not implemented
You should use either gchartrb or googlecharts depending on code taste and exact needs.
Google Charts API is not a good solution for exact and scientificly correct graphs since it seems to render the data, labels and grids independently. Labels for example are spaced evenly along a certain axis and have no connection to the actual data points in the graph.
- google charts on rails
- google charts api
- ruby on rails