活动管理仪表板栏中的图表集成

时间:2015-10-28 10:14:26

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

我的信息中心

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是否正常工作?

1 个答案:

答案 0 :(得分:3)

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

然后在您的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