Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def index
- if params[:start_date] && params[:start_date].is_a?(Hash)
- #the user provided a date
- @start_date = Date.new(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day])
- elsif params[:start_date]
- #they provided a date in string format (probably for the json)
- @start_date = Date.parse(params[:start_date])
- else
- #lets use a default date
- @start_date = 3.months.ago.to_date
- end
- #do the same thing for end date
- if params[:end_date] && params[:end_date].is_a?(Hash)
- #the user provided a date
- @end_date = Date.new(params[:end_date][:year].to_i, params[:end_date][:month].to_i, params[:end_date][:day])
- elsif params[:end_date]
- #they provided a date in string format (probably for the json)
- @end_date = Date.parse(params[:end_date])
- else
- #lets use a default date
- @end_date = 3.months.ago.to_date
- end
- respond_to do |wants|
- wants.html {
- @graph = open_flash_chart_object( 600, 300, stats_url(:format => :json, :start_date => @start_date, :end_date => @end_date))
- }
- wants.json {
- @stats = Stat.between_dates(@start_date, @end_date) #or whatever your find method is called.
- #build a chart
- chart = OpenFlashChart.new( "Data between #{@start_date} and #{@end_date}" ) do |c|
- #TODO make the bar chart have axis values as well for the dates....
- c << BarGlass.new( :values => @stats.map{|s| s.value} )
- end
- render :text => chart, :layout => false
- }
- end
- end
Add Comment
Please, Sign In to add comment