yellowskull
yellowskull

Reputation: 177

Rails Highchart not looping

I'm using Lazy Highcharts to generate a graph from my database. I have the loop situated in my controller and it loops the columns correctly, but the categories it only lists the last inputed site, not sure why this is.

Controller

def index
  @nutritiontrials = Nutritiontrial.all

  @plantstand = LazyHighCharts::HighChart.new('graph') do |f|
    @nutritiontrials.each do |trial|
      f.xAxis(:categories => [trial.site])
      f.series(:type => 'column', :name => 'Plant Stand Treated', :data => [trial.nil_plant_stand_est], :color => '#00463f')
    end
  end
end

Upvotes: 1

Views: 108

Answers (1)

yellowskull
yellowskull

Reputation: 177

 @nutritiontrials = Nutritiontrial.all
    sites = []
    plant_stand = []

    @nutritiontrials.each do |trial|
      sites << trial.site
      plant_stand << trial.nil_plant_stand_est
    end  

    @plantstand = LazyHighCharts::HighChart.new('graph') do |f|
      f.xAxis(:categories => sites)
      f.series(:type => 'column', :name => 'Plant Stand Treated', :data => plant_stand, :color => '#00463f')
    end

Upvotes: 1

Related Questions