【问题标题】:Charts integration in active admin dashboard rails活动管理仪表板轨道中的图表集成
【发布时间】:2016-01-28 01:30:15
【问题描述】:

我的仪表板

section "Graph", do
div do
    render 'graph'
    end
end

_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]
        }]
    });
});

我将 _graph.html.erb 放在哪个文件夹中以便加载。之后里面的 JavaScript 能正常工作吗?

【问题讨论】:

    标签: javascript jquery ruby-on-rails charts asset-pipeline


    【解决方案1】:

    活动管理员上的图表集成非常简单,您只需在 Gemfile 中获取 chartkick

    然后在您的 dashboard.rb 中,您可以在列中创建另一个面板并显示您的图表。 示例:

      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
    

    【讨论】:

    • 哇。多么棒的建议和伟大的宝石。
    猜你喜欢
    • 2014-04-16
    • 2012-11-08
    • 2012-06-26
    • 2016-08-16
    • 2017-11-14
    • 2019-09-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多