5

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

Sabyasachi Ghosh
  • 2,765
  • 22
  • 33

4 Answers4

4

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" %>
Aniruddha
  • 3,157
  • 4
  • 32
  • 48
4

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)

xxjjnn
  • 14,591
  • 19
  • 61
  • 94
0

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

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

And:

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

TK-421
  • 10,598
  • 3
  • 38
  • 34
0

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

Mamuh
  • 68
  • 6