Gruff

Hi!
I am using Gruff as per the directions of
http://nubyonrails.com/articles/2005/11/19/gruff-with-rails-typo-rewrite
but
it doesn’y show me the Graph. It only shows me the background image of
that
graph.
Here is the controller method for it:

def bar_graph_report
built_array = []
g = Gruff::Pie.new(400)
g.title = “Optionwise polling”
g.font = File.expand_path(‘artwork/fonts/Vera.ttf’, RAILS_ROOT)
g.labels = { 0 => ‘Mon’, 2 => ‘Wed’, 4 => ‘Fri’, 6 => ‘Sun’ }

@poll = Poll.find(params[:id])
@total_votes = (@poll.option_one_count) + (@poll.option_two_count) +
(@
poll.option_three_count)
built_array[0] = ((@poll.option_one_count)/@total_votes) * 100
built_array[1] = ((@poll.option_two_count)/@total_votes) * 100
built_array[2] = ((@poll.option_three_count)/@total_votes) * 100
g.data(‘option wise voting’, built_array)

send_data(g.to_blob,
:disposition => ‘inline’,
:type => ‘image/png’,
:filename => “bart_scores.png”)
end

What could be the problem?
Thanks and regards,
Swanand

Its been a while since I’ve looked at the docs for it. One thing is
dont worry about calculating total votes.
Also try feeding g.data one option at a time like so
@poll.options do |option|
g.data(option.name, option.votes)
end
Hope this helps.

  • Richard