Forum: Ruby on Rails Gruff

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Swanand D. (Guest)
on 2007-04-02 13:29
(Received via mailing list)
Hi!
   I am using Gruff as per the directions of
http://nubyonrails.com/articles/2005/11/19/gruff-w...
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
Richard L. (Guest)
on 2007-04-02 18:17
(Received via mailing list)
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
This topic is locked and can not be replied to.