Thanks to Geoffrey Grosenbach for writing the great little Gruff graphing library! It's a fine piece of work and let me create some nice graphs for the indi backend.
More specifically, I wanted to do some time based graphs. Here's some code to create a list of crumpets sold to date:
The graph produced looks like this:
Couple of misc notes:
- This assumes that the
Crumpet
object has a Railscreated_on
field - The
if day % 3 == 0
just spaces out the date labels a bit - This code can go right into a controller and, if you put it in an action called
crumpetchartaction
, can be called from a view with something like - If you're using Gruff, consider donating a few bucks to Geoffrey for encouragement's sake. Yup, I did :-)
There are some tricky bits in getting Gruff set up; I've seen posts on the Rails list and elsewhere from folks having problems. Here are some notes on getting the fonts set up:
- ImageMagick (or RMagick? not sure) wants to default to the font
ariel.ttf
. This didn't come with Fedora Core, but I got it by downloading and installingmsttcorefonts-1.2-3.src.rpm
. - Of course, that's just a source RPM, so I
cd /usr/src/redhat/SPECS
and did arpmbuild --ba msttcorefonts.spec
. - Oops, it needs
cabextract
, so I got that from here; I got thecabextract-1.1-1.i386.rpm
file and installed it. - Back to
/usr/src/redhat/SPECS
, runningrpmbuild
again, but it can't download the fonts from the SourceForge mirror. Edited themsttcorefonts.spec
file, changed the first character of line 10 from a "#" to a "%" - in other words, switched the SourceForge mirror selection from the telia mirror to the umn mirror. Now therpmbuild
command works fine, it builds the RPM, yay! - Now do a
rpm -i /usr/src/redhat/RPMS/noarch/msttcorefonts-1.2-3.noarch.rpm
, that installs the fonts. But ImageMagick still couldn't find them, so I did amkdir /usr/share/fonts/default/TrueType
and acp /usr/X11R6/lib/X11/fonts/msttcoreconts/*.ttf /usr/share/fonts/default/TrueType/
. After that... success!