Skip to content

Instantly share code, notes, and snippets.

@oscardelben
Created February 24, 2011 21:40
Show Gist options
  • Save oscardelben/842945 to your computer and use it in GitHub Desktop.
Save oscardelben/842945 to your computer and use it in GitHub Desktop.
def distribution_chart_helper(width,height,sent,click, hist_sent, hist_click)
max_val = [sent,click, 1].max
hist_max_val = [hist_sent, hist_click, 1].max
hist_sent = max_val.to_f * hist_sent / hist_max_val.to_f
hist_click = max_val.to_f * hist_click / hist_max_val.to_f
data = [sent,click, hist_sent, hist_click].map{|d| [d,0.01].max}.join("|")
legend = "sent|clicks"
data_labels = (0..1).map{|i| "N*f0*,000000,#{i},-1,11"}.join("|")
series_colors = %Q{76a4fb,405887,76a4fb,405887}
url = %Q{http://chart.apis.google.com/chart?chxt=y,r&chbh=a&chs=#{width}x#{height}&cht=bvg&chf=bg,s,efefef}
url += %Q{&chds=0,#{max_val*1.1}&chxr=0,0,#{max_val}|1,0,#{hist_max_val}}
url += %Q{&chco=#{series_colors}}
url += %Q{&chd=t:#{data}&&chdl=#{legend}}
url += %Q{&chm=#{data_labels}}
url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment