[英]Charts integration in active admin dashboard rails
My Dashboard我的仪表盘
section "Graph", do
div do
render 'graph'
end
end
_graph.html.erb _graph.html.erb
<script type="text/javascript">
$(function(){
new Highcharts.Chart({
chart: {
renderTo: "charts"
},
title: {
text: "Orders"
},
xAxis: {
title: {
text: "X axis"
}
},
yAxis: {
title: {
text: "Y axis"
}
},
series: [{
data: [1,3,5,7]
}]
});
});
In which folder I place that _graph.html.erb so that it can loaded.我将那个 _graph.html.erb 放在哪个文件夹中,以便它可以加载。 is JavaScript in it works correctly after that?在那之后,它里面的 JavaScript 能正常工作吗?
Charts integration on active admin is pretty simple, all you have to use is get chartkick in your Gemfile.主动管理中的图表集成非常简单,您所需要的只是在您的 Gemfile 中获取 chartkick。
Then in your dashboard.rb you can create another panel within a column and show your graph.然后在您的dashboard.rb 中,您可以在一列中创建另一个面板并显示您的图表。 Example:例子:
panel "Top stuff --all name-removed for brevity--" do
# line_chart Content.pluck("download").uniq.map { |c| { title: c, data: Content.where(download: c).group_by_day(:updated_at, format: "%B %d, %Y").count } }, discrete: true
# column_chart Content.group_by_hour_of_day(:updated_at, format: "%l %P").order(:download).count, {library: {title:'Downloads for all providers'}}
# column_chart Content.group(:title).order('download DESC').limit(5).sum(:download)
bar_chart Content.group(:title).order('download DESC').limit(5).sum(:download) ,{library: {title:'Top 5 Downloads'}}
##
# line_chart result.each(:as => :hash) { |item|
# {name: item.title, data: item.sum_download.count}
# }
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.