When I try to render a Mini graph, whithout bind any data to it, the following exception is raised:
NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.+):
C:/Arquivos de programas/ruby/lib/ruby/gems/1.8/gems/gruff-0.2.8/lib/gruff/mini/legend.rb:30:in
`draw_vertical_legend'
C:/Arquivos de programas/ruby/lib/ruby/gems/1.8/gems/gruff-0.2.8/lib/gruff/mini/pie.rb:28:in `draw'
C:/Arquivos de programas/ruby/lib/ruby/gems/1.8/gems/gruff-0.2.8/lib/gruff/base.rb:391:in `to_blob'
/app/controllers/chart_controller.rb:24:in `generate_pie_chart'
C:/Arquivos de programas/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `send'
The following code was used:
# view
<%= image_tag url_for (:controller => 'chart',
:action => 'generate_pie_chart',
:id => 'pie_chart.png') %>
#controller
def generate_pie_chart
g = Gruff::Mini::Pie.new(210)
g.initialize_ivars
g.legend_font_size = 40
g.marker_font_size = 40
g.title_font_size = 40
g.theme = {
:colors => %w(red yellow blue gray orange green black purple pink),
:marker_color => 'white',
:background_colors => %w(white white)
}
send_data(g.to_blob,
:disposition => 'inline',
:type => 'image/png',
:filename => "pie_chart.png")
end
|