yellowskull
yellowskull

Reputation: 177

Array issue in rails and highcharts

I'm having issues in display data from my array in the series section of my lazy highcharts code. The 'dates' variable works fine in the 'f.options[:xAxis][:categories] = dates' section, but comes up blank in the 'f.series(:type => 'area', :name => 'Degree', :data => temps, :color => '#00463f')' and I'm not sure why this is.

The data comes from an uploaded csv file which I have used the paperclip gem to achieve.

Controller

def show
    @soiltemp = Soiltemp.find(params[:id])
    @data = CSV.open(@soiltemp.csv.path, :headers => true, :encoding => 'ISO-8859-1')
    dates = []
    temps = []
    @data.each do |row|  
     dates << row[1]
     temps << row[2]
    end
    @graph = LazyHighCharts::HighChart.new('graph') do |f|
      f.options[:xAxis][:categories] = dates 
      f.series(:type => 'area', :name => 'Degree', :data => temps, :color => '#00463f' ) 
      f.series(:type => 'spline',:name => 'Average', :data => [3, 2.67, 3, 6.33, 3.33]) 
    end
    end

Upvotes: 0

Views: 308

Answers (1)

Peter Alfvin
Peter Alfvin

Reputation: 29389

Highcharts is expecting numbers for the series. You're passing strings in your temps array. Use row[2].to_i (if they are integers) when building up temps.

Upvotes: 2

Related Questions