Guest User

Untitled

a guest
Jun 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. def index
  2. if params[:start_date] && params[:start_date].is_a?(Hash)
  3. #the user provided a date
  4. @start_date = Date.new(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day])
  5. elsif params[:start_date]
  6. #they provided a date in string format (probably for the json)
  7. @start_date = Date.parse(params[:start_date])
  8. else
  9. #lets use a default date
  10. @start_date = 3.months.ago.to_date
  11. end
  12. #do the same thing for end date
  13. if params[:end_date] && params[:end_date].is_a?(Hash)
  14. #the user provided a date
  15. @end_date = Date.new(params[:end_date][:year].to_i, params[:end_date][:month].to_i, params[:end_date][:day])
  16. elsif params[:end_date]
  17. #they provided a date in string format (probably for the json)
  18. @end_date = Date.parse(params[:end_date])
  19. else
  20. #lets use a default date
  21. @end_date = 3.months.ago.to_date
  22. end
  23.  
  24. respond_to do |wants|
  25. wants.html {
  26. @graph = open_flash_chart_object( 600, 300, stats_url(:format => :json, :start_date => @start_date, :end_date => @end_date))
  27. }
  28. wants.json {
  29. @stats = Stat.between_dates(@start_date, @end_date) #or whatever your find method is called.
  30. #build a chart
  31. chart = OpenFlashChart.new( "Data between #{@start_date} and #{@end_date}" ) do |c|
  32. #TODO make the bar chart have axis values as well for the dates....
  33. c << BarGlass.new( :values => @stats.map{|s| s.value} )
  34. end
  35. render :text => chart, :layout => false
  36. }
  37. end
  38. end
Add Comment
Please, Sign In to add comment