I want to draw a pie chart for an array with chartkick but I have seen in the website of chartkick examples of charts to a column in a table like <%= pie_chart Yogurt.group(:flavor).count %>
. There is a way to draw just an array using chartkick.
Check out this part of their website https://chartkick.com/#data -
<%= pie_chart [["Football", 10], ["Basketball", 5]] %>
If you are using a database then do this -
Define it in the controller -
def index
@piechartdata = Sport.pluck(:name, :id)
end
That will give you exactly this format - [["Football", 10], ["Basketball", 5]]
Then in your view -
<%= pie_chart @piechartdata %>