Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Active Admin + Chartkick = Not working?

I was trying to use Chartkick to generate graph that shows on rails active admin dashboard. Here is the tutorial I am using: http://www.patrickedelman.com/simple-charting-for-activeadmin/

However, the graph did not show up, instead, it shows "Loading..."

I already include javascript_include_tag "//www.google.com/jsapi", "chartkick" and gem chartkick is installed, but it still does not work.

Please help! Thank you.

like image 741
Juan Kou Avatar asked Jan 22 '15 20:01

Juan Kou


People also ask

What is Active Admin rails?

Active Admin is a Ruby on Rails plugin for generating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.


2 Answers

Don't forget to add #= require chartkick to active_admin.js.coffee.

To render a chart in AA dashboard, go with:

div class: 'custom-class' do
  h3 'Your name for a chart'
  @metric = Model.group(:attribute).count # whatever data you pass to chart
  render partial: 'metrics/partial_name', locals: {metric: @metric}
end

This file

partial: 'metrics/partial_name'

lays under app/views/metrics/partial_name directory, and could have the following structure:

_partial_name.html.haml:

= javascript_include_tag "//www.google.com/jsapi", "chartkick"
= pie_chart metric 

Having this you should be ok with using chartkick.

like image 87
Andrey Deineko Avatar answered Nov 13 '22 08:11

Andrey Deineko


For Active Admin on Rails 6

After add the gem "chartkick", you need to add to app/assets/javascripts/active_admin.js:

//= require chartkick
//= require Chart.bundle
like image 36
Pedro Schmitt Avatar answered Nov 13 '22 08:11

Pedro Schmitt