Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 387
Sabyasachi Ghosh Avatar asked Dec 14 '14 17:12

Sabyasachi Ghosh


2 Answers

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" %>
like image 189
Aniruddha Avatar answered Sep 26 '22 21:09

Aniruddha


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)

like image 41
xxjjnn Avatar answered Sep 24 '22 21:09

xxjjnn