views:

97

answers:

2

For my school project I am buiding a time registration program. It is my first in ruby on rails, so even the simplest things are hard . ;)

The situation:

Users can work on a project, and I want to display in a chart how many hours each user worked on a project, let's say, each month. The chart plugin works like this:

first_serie = OpenFlashChartLazy::Serie.new(
[["2008-1",100],["2008-2",120],["2008-3",130]],
{:title=>"name_of_user1",:start_date=>Time.mktime(2008,1,1),:items=>8})

This adds a new line in the graph.

my question is: how can I loop through all my users and for each fill a new series with data from the database?

+3  A: 

I have no idea how you generate all the data for Serie.new, but you can get started using this:

@series = []
users = User.find(:all)
users.each do |user|
  @series << OpenFlashChartLazy::Serie.new(blah, blah, blah)
end

This will add all of the added Serie objects to an array.

Pesto
Thank you very much for insight this makes things [email protected] do |serie| bar_graph.add_serie(serie)end
arcooverbeek
+1  A: 

As a follow up to Pesto would be nicer to use inject.

@series = User.all.inject([]) do |mem, user|
  mem << OpenFlashChartLazy::Serie.new(user.foo, user.bar, user.foobarbob)
end

Same code, just doesnt have a @series = []

Omar Qureshi