1 class SparklinesController < ApplicationController
3 # Handles requests for sparkline graphs from views.
5 # Params are generated by the sparkline_tag helper method.
8 # Make array from comma-delimited list of data values
10 if params.has_key?('results') && !params['results'].nil?
11 params['results'].split(',').each do |s|
16 send_data( Sparklines.plot( ary, params ),
17 :disposition => 'inline',
19 :filename => "spark_#{params[:type]}.png" )
23 # Use this type of method for sparklines that can be cached. (Doesn't work with the helper.)
25 # To make caching easier, add a line like this to config/routes.rb:
26 # map.sparklines "sparklines/:action/:id/image.png", :controller => "sparklines"
28 # Then reference it with the named route:
29 # image_tag sparklines_url(:action => 'show', :id => 42)
31 send_data(Sparklines.plot(
32 [42, 37, 89, 74, 70, 50, 40, 30, 40, 50],
33 :type => 'bar', :above_color => 'orange'
35 :disposition => 'inline',
37 :filename => "sparkline.png")