Subscribe to the MPC blog rss feed feed-icon-14x14
 

Representing Data With Gruff Bar Charts



Posted on 10:39PM on 11/06/2008
Tags: gruff, complainatron

I'm currently working on Complainatron on the side. It's a simple but fun application that allows anonymous bitching and complaining. People like to do that, right? It also attempts to capture geographical information from users and does various things with it - including using the geographical data to create bar charts. For this task, I use Gruff (created by Geoffrey Grosenbach), a nice ruby wrapper around RMagick/ImageMagick.

Gruff's homepage explains how to install it, so I won't go into much detail. Suffice it to say that you need ImageMagick, RMagick, and, obviously, Gruff.

Creating a bar chart

I've got data that is essentially a collection of ComplaintCategory objects. Each complaint category has a category name and the number of submissions against that category. What I want to do in the case of this example, is to create a bar chart like that shown below.

Popularity

Below is an example of how I could go about doing this (in the application, it's actually a lot more abstracted, but this works as an example).

Naturally, it's necessary to pass in options to let Gruff know how you want it to create the chart. As well, the data to chart needs to be present. Because I have a collection of ComplaintCategory objects, I can set the chart labels to an array the contains the category names. I can set the actual data for the chart to an array that contains the counts for each category.

On the whole, Gruff is easy to use and does a nice job. I wanted to post this information because although there are various examples using Gruff out there, there weren't too many discussing creating bar charts.

Hope someone finds it useful!

2 Comments (Show) (Comments are closed for this post)

 
Please note that I am currently unavailable for any large, long term work.