Search code examples
javascriptruby-on-railsrubychartkick

Impressionist and Chartkick


I would like to display a simple bar chart of views against Posts. I'm using the Impressionist gem to track the number of impressions on each Post, and I'm using the Chartkick gem to create the bar chart.

This is the code I have in my view:

<%= bar_chart @posts.map{|post|
    {name: post.title, data: post.impressionist_count }
} %>

Both gems are working fine in other areas, and the above code passes without any errors, but what gets rendered is an empty bar chart with an accurate legend.

It seems like there should be a simple solution, but I can't find it!

Any help would be appreciated.


Solution

  • You can do:

    bar_chart @posts.map{|post| [post.title, post.impressionist_count] }