James

Graphing and charting data in Ruby on Rails

July 15th, 2008 by James

Despite my documented tendency to be a secret squirrel about what we are doing, I believe that I can let this particular cat out of the bag. We are going to be using graphs to do something within the site at some stage - no surprises here really as we are dealing with numbers so it is really a logical progression. As we have also mentioned previously, we are using Ruby on Rails as the framework to develop PocketSmith.

There are a number of different methods of generating graphs within rails web applications - the two that I am most familiar with (but have never implemented properly) are Gruff and Scruffy. Both of these require the installation of the RMagick / ImageMagick libraries onto the machine that the web application is running on. I was looking into how to go about this tasks and just about to start pounding my console, but then I stumbled upon the Google Charts API.

Basically, Google pumps out a lot of charts and graphs for its applications, and they have opened up the API (or, part of the API) to the community at large. The charts that are created are generated from a URL, which you just throw into an image tag and you are good to go.

Fortunately, there are also a few ruby / rails wrappers for the use of the chart API, making things extremely simple:

So with these in mind, I had a decision to make. Now I am not one for things being difficult, so I went for the first option on the list, Google Charts. The reason for this choice is that the documentation is very clear and linear in nature, examples are concise, and it all feels intuitive. This means I could get a chart up and running very quickly; although the syntax is fairly similar between all of the listed Ruby on Rails plugins. Additionally, the Google Charts plugin is installed as a gem as opposed to cluttering up the PocketSmith plugins folder too much. And the documentation is, sorry, far prettier than the RDoc’s for the gchart’s :D
Now we have charts to play with. Although they do not appear to be as flexible as Gruff or Scruffy, they do make up for this shortcoming in a variety of ways:
  • No additional libraries to install beyond the gem / plugin for the ruby wrapper of your choice
  • No load on the application server when generating the graphs - Google does it for you
  • Simple configuration and well documented API
  • Completely free use of the API, with up to 250,000 requests in a day being available without notifying Google
However as Google is generating these charts from the data sent via the URL, and offering the service for free (and they are a publicly owned corporation driven by profit at the end of the day) some people are concerned about the storage and use of this data. Google states in the Google Chart API FAQ:
The chart data included in the HTTP request is saved in temporary logs for no longer than two weeks for internal testing and debugging purposes.
Of course you should understand that if your chart appears in an image tag on a public webpage it could be crawled.
Sufficiently vague, yes. Enough to be concerned about what they are doing with the data? Not really, but then again I am not the paranoid type. Talk to Francois about that.

Tags: , , ,

6 Responses to “Graphing and charting data in Ruby on Rails”

  1. Dan Says:

    Good luck with your venture guys (Hi Jase!). Maybe it’s overkill for what you are doing, but have you had a look at YUI, specifically the chart functionality?

    http://developer.yahoo.com/yui/examples/charts/index.html

    Obviously more client heavy than just returning an image, but perhaps a little more flexible.

  2. OK, I admit I was wrong - charting in Rails Redux | PocketSmith Says:

    [...] PocketSmith Keeping it simple, keeping it real. « Graphing and charting data in Ruby on Rails [...]

  3. James Says:

    @ Dan - thats pretty cool man, cheers for flicking through that link. Actually went with Flash in the end; YUI would be a bit overkill, plus would add another js library to the prototype / scriptaculous that we are currently using :)

    Thanks for reading :D

  4. Dan Says:

    The YUI chart functionality uses a combination of flash and Javascript. It seems pretty similar to the chart solution you ended up using, which admittedly, I had not seen before.

    YUI provides a lot of different functionality, but the YUI codebase is pretty modular, so you only need to include the bits you want to use. That said, I understand your concerns about using yet another javascript library.

    Good luck with everything.

    Dan

  5. Jason Says:

    Hey Dan, thanks for the heads-up! It’s great to be developing at a time where we can leverage off a range of technologies. Some of the flash charting libraries out there that are licensed look amazing - if not borderline cheesey - but hey! http://www.fusioncharts.com/

    Cheers for keeping an eye out! Hope all’s well in the land of the rising sun bro :-)

  6. Websites tagged "rmagick" on Postsaver Says:

    [...] - Graphing and charting data in Ruby on Rails saved by swolfort2008-09-17 - E X P R E S S I C A » Blog Archive » How to install RMagick Gem [...]

Leave a Reply