Sparklines are now available as a gem, and as a Rails generator! There is also a RubyForge Project.
In order to not conflict with the existing Nitro Spark Ruby project, the name has been changed to ’Sparklines.’ So if you have tried it out in the last few days, change your code to reference ”sparklines” instead of ”spark.” The helper tag has also been changed to the singular sparkline_tag.
Also, there is a new :line_color option so you can set the color of the smooth graph’s line. Thanks to all those who offered suggestions.
At any rate, download the newest version!
sudo gem install sparklines sudo gem install sparklines_generator
Or download here for manual installation:
If you’re using Rails, you only have three more steps to get going:
Note: You can still copy ‘sparklines.rb’ to your app’s ‘lib’ directory if you are working on a server without root access.
After installing both gems, you can run the Rails generator to copy the Sparkline controller and helper files.
ruby script/generate sparklines
Open up config/environment.rb and add the following line to the bottom of the file:
Now, open a controller where you would like to use sparklines. Add the helper:
class SpecialReportController < ApplicationController helper :sparklines end
Now you are in business! Go nuts in any of those controllers’ views!
<%= sparkline_tag [10,20,30], :type => 'pie' %>
No function sparklines_tag The helper function has been changed to the singular “sparkline_tag” instead of the plural. If you downloaded it during the 15 minutes that the plural version was up, just update your gem (‘gem install sparklines_generator’) and re-generate the files in your rails app (‘rails script/server generate sparklines’).
RMagick gem isn’t found If you installed RMagick separately of the gem system, you might have to reinstall. I just re-installed with “gem install rmagick” and it worked fine. If not, try editing your Magick-config file (mine was in /usr/local/bin) to remove the -lcms and/or -ltiff flags.
RMagick is installed, but graphs won’t show up If your server was running before you installed the gems, you might have to restart WEBrick or your FCGI processes.