Post by Peter Cooper on August 17th, 2006

Scruffy: A beautiful graphing toolkit for Ruby

Scruffy

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.)

5 Responses to “Scruffy: A beautiful graphing toolkit for Ruby”

  1. #1
    Sean Cribbs Says:

    Not a big deal, but might that first line of the code sample be missing a do |graph| ?

  2. #2
    brasten Says:

    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’)

  3. #3
    Peter Cooper Says:

    Oops. Sorry about that. It was a bit of a quick hack together. I will now fix with your code. Thanks!

  4. #4
    Peter Cooper Says:

    Now fixed.

  5. #5
    brasten Says:

    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. :)