Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Created January 10, 2010 20:57
Show Gist options
  • Save markmarkoh/273767 to your computer and use it in GitHub Desktop.
Save markmarkoh/273767 to your computer and use it in GitHub Desktop.
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[0..@labels.length-2]
@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