Rails ActiveAdmin 数据图表

dawei · 2018年10月26日 · 1631 次阅读

Gemfile

Gemlist:

#Gemfile
gem 'groupdate'
gem "chartkick"

执行$ bundle install

ActiveAdmin 引入图表 js 库

#config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
  config.register_javascript 'https://www.gstatic.com/charts/loader.js'
end
# app/assets/javascripts/active_admin.js.coffee
#= require active_admin/base
#= require chartkick

ActiveAdmin 添加图表页面

$ rails g active_admin:page StuUserChart
Running via Spring preloader in process 87926
      create  app/admin/stu_user_chart.rb

#  app/admin/stu_user_chart.rb
ActiveAdmin.register_page "StuUserChart" do
  content do
    #para column_chart [["2016-01-01", 30], ["2016-02-01", 54]], stacked: true, library: {colors: ["#D80A5B", "#21C8A9", "#F39C12", "#A4C400"]}
    para line_chart StuUser.group_by_day(:created_at).count
  end
end

有帮助的链接

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号