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:


To save you the time, here is a quick comparison between the three:

Googlecharts

install: gem install googlecharts

Example:

googlecharts gist
Pros:
  • 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

Cons:

  • not implemented grid, line_thickness, and ranges (to my knowledge). This is fairly easy to implement by yourself using the custom option though.


gchartrb

install: gem install gchartrb

Example:

gchartrb gist

Pros:

  • block syntax is always nice
  • easy handling of axises (above)

Cons:

google-charts-on-rails
install: script/plugin install http://google-charts-on-rails.googlecode.com/svn/google_charts_on_rails/

Example: (i have none of my own) google-charts-on-rails gist
Pros:

  • it's not nothing

Cons:

  • weird method_missing -like syntax
  • poor docĀ 
  • much of Google Charts API not implemented

Conclusion:
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.

Categories

  • ruby
  • newsdesk
  • googlecharts
  • google charts on rails
  • google charts api
  • gchartrb
  • ruby on rails
  • developer