Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Chartkick in Rails 4.0

How can i use Chartkick in rails 4.0.

in Gem I added:

gem "chartkick"

and in my view for example i added this:

<%= pie_chart({"Football" => 10, "Basketball" => 5}) %>

but the page only show Loading... generated Html:

<div id="chart-1" style="height: 300px; text-align: center; color:
#999; line-height: 300px; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">   Loading... </div> <script type="text/javascript">   new Chartkick.PieChart("chart-1", {"Football":10,"Basketball":5}, {}); </script>
like image 333
Abolfazl Mahmoodi Avatar asked Oct 02 '13 18:10

Abolfazl Mahmoodi


3 Answers

To get chartkick working in Rails 4, I did the following:

1. Added chartkick gem to my Gemfile (bundle install)

gem 'chartkick'

2. Downloaded Google jsapi file into my vendor directory

/railsapp/vendor/assets/javascripts/jsapi.js

3. Added chartkick and jsapi to my application.js

//= require jsapi
//= require chartkick

After that, charts showed up on a consistent basis.

like image 166
Jeffrey Harrington Avatar answered Oct 18 '22 13:10

Jeffrey Harrington


Be sure to include the JavaScript files before the charts.

<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
like image 18
Andrew Kane Avatar answered Oct 18 '22 11:10

Andrew Kane


Loading your charts superfast

i am using highcharts here as it do not require you to connect each time to google server

add this gem

gem "chartkick"

then download highchart.js from here http://www.highcharts.com/download

paste the file in your app/vendor/assets/javascript/highchart.js

open your application.js and require these two files

//= require highcharts.js
//= require chartkick

after this you are good to go and your charts will load within a blink

like image 5
Lalit Yadav Avatar answered Oct 18 '22 11:10

Lalit Yadav