Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created December 19, 2011 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancom/1495267 to your computer and use it in GitHub Desktop.
Save stephancom/1495267 to your computer and use it in GitHub Desktop.
Simple code to generate a Google Charts pie chart url
# 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