Created
January 10, 2010 20:57
-
-
Save markmarkoh/273767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pie(data_array) | |
@labels = "" | |
@data_str = "" | |
@data = [] | |
@sum = 0 | |
data_array.find().to_a.each do |f| | |
@labels += "#{f['_id']}|" | |
@sum += f['value']['count'].to_i | |
@data.push(f['value']['count'].to_i) | |
end | |
@data.each do |d| | |
@num = d/(@sum + 0.0) * 100 | |
@data_str += "#{@num.round}," | |
end | |
@labels = @labels[[email protected]] | |
@data_str = @data_str[0..@data_str.length-2] | |
return <<-HTML | |
<img src="http://chart.apis.google.com/chart?chs=450x200&chd=t:#{@data_str}&cht=p3&chl=#{@labels}" /> | |
HTML | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment