Created
December 19, 2011 03:35
-
-
Save stephancom/1495267 to your computer and use it in GitHub Desktop.
Simple code to generate a Google Charts pie chart url
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
# values is expected to be hash whose keys are the names of the pie segments | |
def chart_url(values, size = '300x125') | |
colors = %w(FF9900 324C8E ff0000 FF69B4 1E90FF 9ACD32 DAA520 40E0D0) | |
basic_chart = {:chs => size, :cht => 'p3', :chco => colors.join('|')} | |
chart_params = basic_chart.merge( :chd => 't:'+values.values.join(','), | |
:chdl => values.keys.map { |f| "#{f} (#{values[f]})"}.join('|'), :chtt =>'name of chart') | |
"http://chart.apis.google.com/chart?#{chart_params.to_query}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment