javascript - Charts integration in active admin dashboard rails - Stack Overflow

My Dashboardsection "Graph", dodiv dorender 'graph'endend_graph.html.erb<scrip

My Dashboard

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

In which folder I place that _graph.html.erb so that it can loaded. is JavaScript in it works correctly after that?

My Dashboard

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

In which folder I place that _graph.html.erb so that it can loaded. is JavaScript in it works correctly after that?

Share Improve this question edited Apr 10, 2021 at 18:20 Robin Daugherty 7,5344 gold badges47 silver badges60 bronze badges asked Oct 28, 2015 at 10:14 user5496955user5496955
Add a ment  | 

1 Answer 1

Reset to default 6

Charts integration on active admin is pretty simple, all you have to use is get chartkick in your Gemfile.

Then in your dashboard.rb you can create another panel within a column and show your graph. 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745090484a4610665.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信