Sabyasachi Ghosh
Sabyasachi Ghosh

Reputation: 2785

ReferenceError: Chartkick is not defined

I am using chartkick gem to display chart. I have followed the proper installation documentation but whenever I am trying to use their methods like

timeline [["Washington", "1789-04-29", "1797-03-03"], ["Adams", "1797-03-03", "1801-03-03"], ["Jefferson", "1801-03-03", "1809-03-03"]]

It's showing error in the firebug ReferenceError: Chartkick is not defined

Upvotes: 5

Views: 5199

Answers (4)

Mamuh
Mamuh

Reputation: 88

this worked for me:

including:

<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= yield :charts_js %>

in application.html.erb + following the documentation steps

as per https://github.com/ankane/chartkick/issues/499

Upvotes: 1

xxjjnn
xxjjnn

Reputation: 15239

Lets walk through all potential pitfalls (non-highcharts solution)


GEMFILE:

make sure to run bundle install afterwards

include 'chartkick'

APPLICATION.JS:

in your config/environments/development.rb you might have set config.assets.compress = true and config.assets.compile = true and config.serve_static_files = true, which would mean you would need to recompile your assets to see changes in development.

//= require chartkick

HAML:

javascript include line begins '=' not '-'. @report.data should be active record relation

= javascript_include_tag '//www.google.com/jsapi', 'chartkick'
= pie_chart @report.data

SERVER:

If using spring, try spring stop. Restart your rails server. Force reload page cmd+shift+R or ctrl+shift+R (not all browsers can do this)

Upvotes: 4

Aniruddha
Aniruddha

Reputation: 3327

Depending on which charting library you prefer, you need to include it's javascript path in your view file. That solved the issue for me.

<%= javascript_include_tag "path/to/highcharts.js", "chartkick" %>

Upvotes: 4

TK-421
TK-421

Reputation: 10763

I'd verify that everything's in place per:

https://github.com/ankane/chartkick/issues/3

And:

https://github.com/ankane/chartkick/issues/1

Upvotes: 0

Related Questions