Highcharts gem 不工作
Highcharts gem not working
我正在尝试为懒惰的高图表 gem.
的用户创建权重线图
我目前 users_controller
def show
@user = User.find(params[:id])
@weights = Weight.where(user_id: @user.id)
@weight_hash = @weights.to_json
@chart = LazyHighCharts::HighChart.new('graph') do |f|
f.title(:text => "Historical Weights")
f.xAxis(:type => 'datetime', :title => {:text =>'Date'})
f.yAxis(:title => {:text => "pounds"})
f.series(:name => 'Weight', :data => @weight_hash)
f.chart({defaultSeriesType => 'line'})
end
end
在我的体重模型中,我有:
class Weight < ActiveRecord::Base
belongs_to :user
def as_json(*args)
{
:weight => self.weight,
:date => self.date
}
end
end
然后在我的 users/show.html.erb 我有
<%= high_chart("Weight", @chart) %>
但我收到错误
undefined local variable or method `defaultSeriesType' for
#
我不确定应该如何声明此方法,因为它是 gem 的一部分。谁能解释一下这是怎么回事?
这一行:
f.chart({defaultSeriesType => 'line'})
你好像忘记给 defaultSeriesType
添加一个冒号来使它成为一个符号,所以 Ruby 认为它是一个 variable/method。尝试将其更改为:
f.chart({:defaultSeriesType => 'line'})
...与其他哈希一样。
我正在尝试为懒惰的高图表 gem.
的用户创建权重线图我目前 users_controller
def show
@user = User.find(params[:id])
@weights = Weight.where(user_id: @user.id)
@weight_hash = @weights.to_json
@chart = LazyHighCharts::HighChart.new('graph') do |f|
f.title(:text => "Historical Weights")
f.xAxis(:type => 'datetime', :title => {:text =>'Date'})
f.yAxis(:title => {:text => "pounds"})
f.series(:name => 'Weight', :data => @weight_hash)
f.chart({defaultSeriesType => 'line'})
end
end
在我的体重模型中,我有:
class Weight < ActiveRecord::Base
belongs_to :user
def as_json(*args)
{
:weight => self.weight,
:date => self.date
}
end
end
然后在我的 users/show.html.erb 我有
<%= high_chart("Weight", @chart) %>
但我收到错误
undefined local variable or method `defaultSeriesType' for #
我不确定应该如何声明此方法,因为它是 gem 的一部分。谁能解释一下这是怎么回事?
这一行:
f.chart({defaultSeriesType => 'line'})
你好像忘记给 defaultSeriesType
添加一个冒号来使它成为一个符号,所以 Ruby 认为它是一个 variable/method。尝试将其更改为:
f.chart({:defaultSeriesType => 'line'})
...与其他哈希一样。