>我在懒惰的 highcharts 代码的系列部分中显示数组中的数据时遇到问题。"日期"变量在"f.options[:xAxis][:categories] = 日期"部分中工作正常,但在"f.series(:type => 'area', :name => '度', :d ata => temps, :color => '#00463f')"中出现空白,我不确定为什么会这样。
数据来自上传的csv文件,我使用回形针宝石来实现该文件。
控制器
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
Highcharts期待该系列的数字。您正在temps
数组中传递字符串。在构建temps
时使用row[2].to_i
(如果它们是整数)。