user532339
user532339

Reputation:

Cannot implement lazy high chart receiving errors

I am trying to implement lazy high charts using the following github site GitHub I have done the following steps

What is confusing is I reach the point where it tells you to put the code into the controller but doesn't tell you where exactly. So I tried doing some of the following and these were the results

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

Outcome =

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

View

    <%= 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) %>

Outcome =

 LoadError in DashboardController#index

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

I tried these both ways and recieved different errors. I am still new to ror and javascript, so this may seem fairly easy to the you. Is there any suggestion or any advice where I am going wrong.

Upvotes: 2

Views: 2052

Answers (2)

Owl
Owl

Reputation: 31

I was having a similar problem.. The chart was not being shown in the page

Controller code was ok Page code was ok

But the hight charts installation didn't include the JS in the app/assets/application.js

if you face this problem, include the following code in app/assets/application.js

//= require highcharts/highcharts
//= require highcharts/highcharts-more
//= require highcharts/highstock

Upvotes: 2

Gazler
Gazler

Reputation: 84140

Your main issue is this code block:

@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

Should be inside a controller action.

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

Also I'd recommend installing it by adding the gem to your Gemfile instead of the plugin installation method.

gem 'lazy_high_charts'

Install gems:

bundle install

Install highcharts:

rails g lazy_high_charts:install

Don't forget this gem also requires jquery, so add the following to your gemfile:

gem 'jquery-rails'

Then install:

bundle

Then create the javascript:

rails g jquery:install

I have created a sample app, you can see it here: https://github.com/Gazler/Highcharts-rails-example

Upvotes: 1

Related Questions