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
Crumpetobject has a Rails
if day % 3 == 0just 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 installing
- Of course, that's just a source RPM, so I
cd /usr/src/redhat/SPECSand did a
rpmbuild --ba msttcorefonts.spec.
- Oops, it needs
cabextract, so I got that from here; I got the
cabextract-1.1-1.i386.rpmfile and installed it.
- Back to
rpmbuildagain, but it can't download the fonts from the SourceForge mirror. Edited the
msttcorefonts.specfile, 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 the
rpmbuildcommand 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 a
mkdir /usr/share/fonts/default/TrueTypeand a
cp /usr/X11R6/lib/X11/fonts/msttcoreconts/*.ttf /usr/share/fonts/default/TrueType/. After that... success!