Prev | Current Page 74 | Next

David Berube

"Practical Reporting with Ruby and Rails"

play_id=p.id
WHERE p.game_id='#{game_id_to_analyze}'
AND
p.player_id='#{player.id}'
GROUP
BY e.event DESC;"
data = []
Event.find_by_sql(sql).each do |row|
bar_chart.data row.event, (row.average_time.to_i/1000)
end
bar_chart.labels = {0=>'Time'}
bar_chart.write("#{pic_dir}/player_#{player.id}.png")
end
Each row contains an event description and an average time. You loop through these
rows, and for each of those rows, you add a bar to your chart using the data method. After
that, you set the column label and write your chart to a file.
As you can see, even though Listing 3-4 is more complex than Listing 3-1, it??™s still
fairly simple.
Now let??™s try creating another type of chart with Gruff.
Creating a Line Chart
Suppose the management at Transmegtech Studios wants you to create a single chart
containing the average build time for each event for all players. You can do that with a
line chart. Listing 3-5 shows the code to create a single chart summarizing all of the
players.
Listing 3-5. Creating a Line Chart for All Player Events (all_players.


Pages:
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
Wanny spa pozycjonowanie karty kredytowe bmw e32 nawadnianie