views:

19

answers:

1

I have a model, ContactEmail that has a date_sent attribute and an email_id, referencing another model Email.

I would like to create a bar graph which shows on the x-axis dates and on the y-axis the number of ContactEmails that were sent on a specific date.

I would like to also do the same, filtered for ContactEmails where email_id equals a specific value.

My end-goal is to have some kind of a bar graph -- I am still researching how to do that, but regardless, it seems like I would need some kind of a time-series array, which I suppose would have date as one element, and the count for the other.

How do I do this?

The graphing solution I am looking at is called Seer:

http://github.com/Bantik/seer

I am using the statistics gem, which is outputting a hash that looks like this:

=> #<OrderedHash {"2010-10-23"=>2, "2010-09-22"=>3, "2010-09-11"=>1, "2010-08-27"=>1, "2010-10-15"=>
1, "2010-09-15"=>1, "2010-08-08"=>2, "2010-10-17"=>14, "2010-10-06"=>2, "2010-09-28"=>1, "2010-10-19
"=>1, "2010-09-20"=>1}>

1) How can I put that in an order? 2) Does Seer recognize null date values?

A: 

Hi You may try to make some Hash

list = {}
ModelName.all.each do |mn|
 date = p.created_at.to_date 
 list[date] = 0 if list[date].blank?
 list[date] += 1
end

you'll get something like

{Fri, 22 Oct 2010=>1021, Sat, 23 Oct 2010=>1}
Bohdan Pohorilets