M
Michael Modic
Hi,
I have been trying for many hours to figure out how to do this, and have
yet to come up with a solution. It's my lack of experience I'm sure and
I hope someone can point me in the right direction.
I have an ActiveRecord resultset that contains rows from a query with
group by clauses. I'm trying to generate a stacked column graph that
will show the number of orders for a period of time stacked by the rep
that generated the orders broken down by date.
The AR result set has the following attributes:
sale_date (date the sale was made - for a single date, there will be a
row for each each rep that had a recorded sale on that date)
sales_rep (the rep - the name of the rep that made the sale on the sale
date)
order_count (the count of orders made by the above rep for the sale
date)
The graph expects an array of dates for the axis. I did:
sale_days = @results.map{ |item | item.sales_day }.uniq
to get a unique set of dates (as they repeat for each rep, but I only
want the unique dates).
I don't have a clue how to get something that allows me to do this:
sales_graph.add( :series, "Sales Rep Name", [a, b, c, d, e] )
where the sales rep name is found in my result set, and the a,b,c... is
the actual count of orders for that rep for each day. I need to do the
sales_graph.add... for each rep found in the resultset. I can handle
that part, if I can figure out how to get the counts for a rep into it's
own array/hash and tied back to the rep.
Please help! :-( If I need to structure my query differently, I can.
Ruby is so beautiful and I know I am missing some easy way to do this
and for the life of me I can't figure it out on my own.
Thanks for any pointers in advance,
M.
I have been trying for many hours to figure out how to do this, and have
yet to come up with a solution. It's my lack of experience I'm sure and
I hope someone can point me in the right direction.
I have an ActiveRecord resultset that contains rows from a query with
group by clauses. I'm trying to generate a stacked column graph that
will show the number of orders for a period of time stacked by the rep
that generated the orders broken down by date.
The AR result set has the following attributes:
sale_date (date the sale was made - for a single date, there will be a
row for each each rep that had a recorded sale on that date)
sales_rep (the rep - the name of the rep that made the sale on the sale
date)
order_count (the count of orders made by the above rep for the sale
date)
The graph expects an array of dates for the axis. I did:
sale_days = @results.map{ |item | item.sales_day }.uniq
to get a unique set of dates (as they repeat for each rep, but I only
want the unique dates).
I don't have a clue how to get something that allows me to do this:
sales_graph.add( :series, "Sales Rep Name", [a, b, c, d, e] )
where the sales rep name is found in my result set, and the a,b,c... is
the actual count of orders for that rep for each day. I need to do the
sales_graph.add... for each rep found in the resultset. I can handle
that part, if I can figure out how to get the counts for a rep into it's
own array/hash and tied back to the rep.
Please help! :-( If I need to structure my query differently, I can.
Ruby is so beautiful and I know I am missing some easy way to do this
and for the life of me I can't figure it out on my own.
Thanks for any pointers in advance,
M.