How to graph impressions with chartkick and impressionist?

106 Views Asked by At

I'm using Impressionist gem to capture impressions for records, and I'm using chartkick to graph the results. What I would like to do, is count the impressions for the current_user's records, and display the count on 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

<%= 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' %>
1

There are 1 best solutions below

0
On

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) %>