Prev | Current Page 63 | Next

David Berube

"Practical Reporting with Ruby and Rails"

new)
CHAPTER 3 n CREATING GRAPHS WITH RUBY 35
graph.add(:bar, 'Sprockets', sprocket_output.map { |s| s[1] })
graph.add(:line, 'Widgets', widget_output.map { |w| w[1] })
graph.point_markers = widget_output.map { |w| w[0] }
graph.render( :width => 800,
:as=>'PNG',
:to => 'widgets_and_sprockets.png')
Save this as widget_chart_scruffy.rb. You can run the script in Listing 3-2 as follows:
ruby widget_chart_scruffy.rb
If you open the file widgets_and_sprockets.png, you should see something similar to
Figure 3-2.
Figure 3-2. Player graph created using Scruffy
As you may have surmised from Listing 3-2, you can add data to a Scruffy graph
using a command like this:
graph.add(:some_chart_type, 'Some_text_for_the_legend', some_array_of_values)
CHAPTER 3 n CREATING GRAPHS WITH RUBY 36
The add command is quite similar to Gruff??™s data method. This example is a bit more
complex, as it parses some hashes and uses the keys of the first hash as labels for the x
axis. (This assumes that they both have the same keys, which may or may not be true.


Pages:
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
Meat Loaf wyniki na żywo Margo Mech Angela McCluskey