ruby on rails - each_with_index only showing last option -


i'm using gruff prawn insert image graph, have bar graph displaying properly, labels showing last label. see image here example.

using prawn (0.15.0) , gruff (0.5.1)

prawn

def initialize(result)  super()  @result = result  show_graph end  def show_graph lint = @result.map {|v| v.lint/227 }  g = gruff::bar.new('540x200') g.data(:lint, lint, '#00463f') @result.each_with_index |v, i| g.labels = {i => v.variety.variety_name} end g.y_axis_label = 'yield (bales/ha)' g.marker_font_size = 16 g.marker_count = 5 g.theme = {:marker_color => '#333333', :font_color => '#333333', :background_colors => %w(#ffffff #ffffff)} g.minimum_value = 0 g.hide_legend = true  g.write("#{rails.root}/app/assets/images/chart.png")  image "#{rails.root}/app/assets/images/chart.png" 

end

controller

@result = result.where('trial_id' => params[:trial_id]).order('lint desc') 

the error make redifining labels hash @ each iteration. instead of doing

g.labels = {i => v.variety.variety_name} 

try :

g.labels[i] = v.variety.variety_name 

and before each, can put :

g.labels = {} 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -