Graphing and charting data in Ruby on Rails
July 15th, 2008 by JamesDespite 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:
- Google Charts - http://googlecharts.rubyforge.org/
- google-charts-on-rails - http://code.google.com/p/google-charts-on-rails/
- gchartrb - http://code.google.com/p/gchartrb/
- gchart - http://gchart.rubyforge.org/gchart/
- 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
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.
Tags: charts, development, graphs, Ruby on Rails






July 16th, 2008 at 7:36 pm
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.
July 17th, 2008 at 4:50 pm
[...] PocketSmith Keeping it simple, keeping it real. « Graphing and charting data in Ruby on Rails [...]
July 17th, 2008 at 7:24 pm
@ 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
July 17th, 2008 at 7:39 pm
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
July 22nd, 2008 at 10:01 am
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
September 20th, 2008 at 4:47 am
[...] - 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 [...]