Rails how to structure data for google charts

I want to use google charts to create a graph that looks like this:

GoogleChart.pie_400x200('Taco Bell'=>0,'Mediterranean'=>2,'Shivas'=>5) 

Given the object say Results (name, count). How to create an object for the GoogleCharts structure as shown above?

thanks

+6
source share
1 answer

Starting with the Results object that you indicated as @results in your comment, the following should work:

 GoogleChart.pie_400x200(@results.map {|r| { r[:title] => r[:percentage] } }) 
+6
source

Source: https://habr.com/ru/post/891578/


All Articles