Post by Peter Cooper on August 17th, 2006
Scruffy: A beautiful graphing toolkit for Ruby

- The Development of a Visual Database Explorer with Ruby
- Pre-processing / normalizing parameters in Rails
- Interesting Rails Tidbits #1



Scruffy is a new graphing toolkit for Ruby developed by Brasten Sager. It's highly customizable and powerful. You can change the backgrounds, mix different types of graph together, change the graphics used for the points, change the line types, etc. You can also render to different types of output. Brasten presents some code examples at his blog. For demonstration, some is repeated below:
graph = Scruffy::Graph.new graph.title = "Comparative Agent Performance" graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0) graph.add :stacked do |stacked| stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120] stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20] stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10] end graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] graph.render(:width => 800, :as => ‘JPG’)
(Thanks to Brasten for fixing my sloppy cut and paste job. See comments.)

Click here to add on del.icio.us
Tweet This









August 18th, 2006 at 12:54 pm
Not a big deal, but might that first line of the code sample be missing a do |graph| ?
August 18th, 2006 at 3:18 pm
No, and the 'end' after graph.point_markers shouldn't be there. That stuff isn't supposed to be in a block:
graph = Scruffy::Graph.new
graph.title = "Comparative Agent Performance"
graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
graph.add :stacked do |stacked|
stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
graph.render(:width => 800, :as => ‘JPG’)
August 18th, 2006 at 3:24 pm
Oops. Sorry about that. It was a bit of a quick hack together. I will now fix with your code. Thanks!
August 18th, 2006 at 3:31 pm
Now fixed.
August 18th, 2006 at 7:37 pm
Thanks Peter! To be honest I'd read that block of code here a dozen times and didn't notice that until Sean said something. :)