Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails how to structure data for Google Charts

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

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

Given an object say Results(name, count). How can I create an object for GoogleCharts's structure as seen above?

Thanks

like image 205
AnApprentice Avatar asked Jun 28 '11 18:06

AnApprentice


1 Answers

Starting with the Results object you listed in your comment as @results, the following ought to work:

GoogleChart.pie_400x200(@results.map {|r| { r[:title] => r[:percentage] } })
like image 63
Luke Avatar answered Nov 03 '22 14:11

Luke