Highcharts宝石不起作用

时间:2016-04-03 02:56:29

标签: ruby-on-rails ruby highcharts rubygems

我试图为懒惰的高级图表宝石创建一个权重线图。

我目前在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) %>

但我收到了错误

  

未定义的局部变量或方法`defaultSeriesType&#39;对于        #

我不确定应如何声明此方法,因为它是gem的一部分。有人可以解释一下发生了什么吗?

1 个答案:

答案 0 :(得分:1)

在这一行:

'use strict'; angular.module('meanGoroApp') .controller('ThoughtsIndexCtrl', function ($scope, $http, Auth, $location, query, socket) { $scope.busy = true; $scope.noMoreData = false; $http.get('/api/thoughts', {params: {query: query}}).success(function(thoughts) { $scope.thoughts = thoughts; socket.syncUpdates('thought', thoughts); if($scope.thoughts.length < 20) { $scope.noMoreData = true; } $scope.busy = false; }); $scope.nextPage = function() { if($scope.busy) { return; } $scope.busy = true; var lastId = $scope.thoughts[$scope.thoughts.length-1]._id; var pageQuery = _.merge(query, {_id: {$lt: lastId}}); $http.get('/api/thoughts', {params: {query: pageQuery}}).success(function(thoughts) { $scope.thoughts = $scope.thoughts.concat(thoughts); $scope.busy = false; if(thoughts.length === 0) { $scope.noMoreData = true; } }); } $scope.isOwner = function(obj) { return Auth.isLoggedIn() && obj && obj.user && obj.user._id === Auth.getCurrentUser()._id; } $scope.isCollected = function(obj) { return Auth.isLoggedIn() && obj && obj.collectedBy && obj.collectedBy.indexOf(Auth.getCurrentUser()._id) !== -1; } $scope.isLoggedIn = function() { if(!Auth.isLoggedIn()) { $location.path('/login'); $location.replace(); return; } } $scope.submit = function() { $http.post('/api/thoughts', $scope.thought).success(function() { $location.path('/users/' + Auth.getCurrentUser()._id); $scope.clearInput(); }); } $scope.clearInput = function() { $scope.thought.main_sentence = null; $scope.thought.sub_sentence = null; } });

看起来您忘记在f.chart({defaultSeriesType => 'line'})添加冒号以使其成为符号,因此Ruby认为它是变量/方法。尝试将其更改为:

defaultSeriesType

...像其他哈希一样。