无法实现延迟高图表接收错误

时间:2011-08-19 09:28:04

标签: javascript ruby-on-rails ruby-on-rails-3 highcharts

我正在尝试使用以下github网站GitHub实现延迟高图表我已完成以下步骤

  • rails plugin install git://github.com/michelson/lazy_high_charts.git

  • @h = LazyHighCharts :: HighChart.new('graph')do | f |     f.series(:name =>'John',:data => [3,20,3,5,4,10,12,3,5,6,7,7,80,9,9])     f.series(:name =>'Jane',:data => [1,3,4,3,3,5,4,-46,7,8,8,9,9,0,0, 9])   端

  • <%= javascript_include_tag'hepercharts'%>
  • <%= high_chart(“my_id”,@ h)%>

令人困惑的是,我达到了这样的程度,即它告诉您将代码放入控制器但不会告诉您确切的位置。所以我尝试了以下一些,这些是结果

1)

class DashboardController < ApplicationController
   access_control do
    actions :index do
      allow :Admin
    end
  end

 def index
   @title = "Welcome to Dashboard"
    before_filter :authenticate, :only => [:index]
  @h = LazyHighCharts::HighChart.new('graph') do |f|
    f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
    f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
        end
     end
    end

结果=

Routing Error

uninitialized constant DashboardController::LazyHighCharts

2)

 class DashboardController::LazyHighCharts < ApplicationController
  before_filter :authenticate, :only => [:index]
  @h = LazyHighCharts::HighChart.new('graph') do |f|
    f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
    f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
  end
   access_control do
    actions :index do
      allow :Admin
    end
  end

  def index
   @title = "Welcome to Dashboard"
  end
end

查看

    <%= javascript_include_tag 'jquery.dataTables.min', 'datatable', 'jquery.dataTables.columnFilter'%>
    <%= stylesheet_link_tag 'demo_table', 'jquery-ui-1.8.4.custom' %> 
    <%= javascript_include_tag 'highcharts'
    <div class="head">
        <h1>Welcome to Dashboard</h1>
    </div>
    <div class="row">
    <div class="um rollover" id="um"><a><center><%= link_to image_tag("User.png", :alt => "User Management", :height => "100"), usermanagement_path %></center><br /><center>User Management</center><br /></a></div>
    <div class="pm rollover" id="pm"><a><center><%= link_to image_tag("Project.png", :alt => "Project Management", :height => "100"), projects_path %></center><br /><center>Project Management</center><br /></a></div>
    <div class="ts rollover" id="ts"><a><center><%= link_to image_tag("Timesheet.png", :alt => "Timesheets", :height => "100"), timesheet_path %></center><br /><center>Timesheets</center><br /></a></div>
    <div class="crm rollover" id="crm"><a><center><%= link_to image_tag("Customer.png", :alt => "Customer Relation Management", :height => "100"), crm_path %></center><br /><center>Customer Relation Management</center><br /></a></div>
    </div>

<%= high_chart("my_id", @h) %>

结果=

 LoadError in DashboardController#index

Expected c:/Users/patterd/documenTS/PadOnRails/app/controllers/dashboard_controller.rb to define DashboardController

我尝试了这两种方式并收到了不同的错误。我仍然是ror和javascript的新手,所以这对你来说似乎相当容易。在我出错的地方有任何建议或建议吗?

2 个答案:

答案 0 :(得分:2)

我遇到了类似的问题..图表没有显示在页面中

控制器代码没问题 页面代码没问题

但是hight图表安装不包括app / assets / application.js中的JS

如果您遇到此问题,请在app / assets / application.js中包含以下代码

// =要求highcharts / highcharts
// =需要highcharts / highcharts-更多
// =需要highcharts / highstock

答案 1 :(得分:1)

您的主要问题是此代码块:

@h = LazyHighCharts::HighChart.new('graph') do |f|
    f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
    f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
end

应该在控制器动作中。

def index
  @h = LazyHighCharts::HighChart.new('graph') do |f|
    f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
    f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
  end
end

另外我建议通过将gem添加到Gemfile而不是插件安装方法来安装它。

gem 'lazy_high_charts'

安装宝石:

bundle install

安装highcharts:

rails g lazy_high_charts:install

不要忘记这个gem也需要jquery,所以将以下内容添加到你的gemfile中:

gem 'jquery-rails'

然后安装:

bundle

然后创建javascript:

rails g jquery:install

我创建了一个示例应用,您可以在此处查看:https://github.com/Gazler/Highcharts-rails-example