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