Oct 22, 2008

Using Gruff with JRuby

A while back, I had a need in one of my Rails apps to generate a graph. Not anything fancy, just a little thing to spit out some lines to make the data easier to visualize. I discovered this gem called Gruff which lets you do some pretty nice things like line charts, pie charts, etc. It's very handy for creating simple graphs that look pretty good. I used it for a graph on this post a while back.

Now, for my current project I have a need to use Gruff again, but this time I'm using JRuby. Normally gems work fine with JRuby, you just go "jgem install x" to install it. However, Gruff depends on RMagick, which (to the best of my knowledge) is written in C and therefore is not compatible with JRuby without a heck of a lot of hacking.

Fortunately, some folks out there somewhere created a gem called rmagick4j, which is a drop-in replacement for RMagick - well at least I think it is, I haven't found anything it does wrong yet. So, here's how to use Gruff with JRuby:
jgem install rmagick4j hoe gruff
And done! Now you can make fancy graphs to impress your boss.

Unfortunately in this day and age, people come to expect more. If you look at the graphs on Google Analytics, they're much fancier than anything that Gruff could ever come up with. Chances are they're using Flex or something, which means you can have a much higher degree of interactivity than you can with just a simple image.
The tradeoff is that with Gruff, you can have a nice-looking graph with about 3-4 lines of Ruby, whereas Flex would probably take you quite a bit longer.

3 comments:

Serabe said...

Hi, Rob,

My nickname is Serabe and I'm the current developer of rmagick4j. I'm so glad you like it but, still, rmagick4j has a lot of issues (the Image class has over 250 methods!). I've been away for two months (currently, I am an exchange student at Sweden) but soon, hopefully this weekend, I'll be back at work.

Thank you very much for your kind words!

Babar said...

Thanks! Nice post! Did you try other graphs for check that rmagick4j works fine ?

http://geoffreygrosenbach.com/projects/show/5

Rob Britton said...

@Serabe: No problem! Thanks for making a great gem! I didn't actually know there was any issues with it, although I guess I haven't used it for too much other than basic image manipulation like cropping/resizing or generating some Gruff graphs.

I didn't test out Gruff with very many graphs (in hindsight I probably should have before writing this post...), we're just using line graphs with our app. I'll have to generate a bunch of other types to see how it works.

Keep up the good work guys!