简体   繁体   English

如何用Chartkick和Impressionist绘制印象图?

[英]How to graph impressions with chartkick and impressionist?

I'm using Impressionist gem to capture impressions for records, and I'm using chartkick to graph the results. 我正在使用Impressionist gem来捕获记录的印象,并且正在使用Chartkick绘制结果图形。 What I would like to do, is count the impressions for the current_user's records, and display the count on chartkick. 我想做的是计算current_user记录的印象数,并在chartkick上显示该计数。 Its a simple issue, but I cannot seem to figure out why the impressions are not being displayed on the graph. 这是一个简单的问题,但我似乎无法弄清楚为什么未在图表上显示印象。 My code is below 我的代码如下

analytics.html.erb analytics.html.erb

<%= line_chart current_user.posts.sum(&:impressionist_count).group_by_hour(:created_at).count, refresh: 60, xtitle: 'Hourly Posts Impression Count', ytitle: 'Amount of Views', label: 'View Count' %>

I found a solution to this problem. 我找到了解决此问题的方法。 Just in case anyone has it in the future. 以防万一将来有人拥有它。 The code below, will inject the sum of the impressions into a hash, and then it will display correctly on the graph. 下面的代码会将展示次数的总和注入到哈希中,然后将其正确显示在图表上。

<%= line_chart current_user.posts.group_by_day(:created_at).count.inject(Hash.new(0)) { |acc, (k,v)| acc[:impressionist_count] += v; acc[k] = acc[:impressionist_count]; acc }.except(:impressionist_count) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM