h1. Googlecharts h2. → 'Sexy Charts using Google API & Ruby' h2. What A nice and simple wrapper for "Google Chart API":http://code.google.com/apis/chart/ h2. Installing
sudo gem install googlechartsh2. The basics This gem supports the following types of charts: !http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld&chxt=x,y&chxl=0:|Mar|Apr|May|June|July|1:||50+Kb(Line)! Gchart.line() !http://chart.apis.google.com/chart?cht=lxy&chs=200x125&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5(line_xy)! Gchart.line_xy() !http://chart.apis.google.com/chart?cht=s&chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&chxt=x,y&chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&chs=200x125(scatter)! Gchart.scatter() !http://chart.apis.google.com/chart?cht=bvg&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00(bar)! Gchart.bar() !http://chart.apis.google.com/chart?cht=v&chs=200x100&chd=t:100,80,60,30,30,30,10(venn)! Gchart.venn() !http://chart.apis.google.com/chart?cht=p&chd=s:world5&chs=200x125&chl=A|B|C|D|E|Fe(pie)! Gchart.pie() !http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=200x100&chl=A|B|C|D(pie_3d)! Gchart.pie_3d() h2. Demonstration of usage install:
sudo gem install googlecharts
require:
require 'gchart'
Gchart.line( :size => '200x300', :title => "example title", :bg => 'efefef', :legend => ['first data set label', 'second data set label'], :data => [10, 30, 120, 45, 72])--- *simple line chart*
Gchart.line(:data => [0, 40, 10, 70, 20])Generate the following url: http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc Inserted in an image tag, it will look like that: !http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc(simple line chart)! *multiple line charts*
Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]])!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m(multiple lines chart)! *set line colors*
Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :line_colors => "FF0000,00FF00")!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m&chco=FF0000,00FF00(line colors)! "more info about color settings":http://code.google.com/apis/chart/#chart_colors *bar chart*
Gchart.bar(:data => [300, 100, 30, 200])!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo(bars)! *Set the bar chart orientation*
Gchart.bar(:data => [300, 100, 30, 200], :orientation => 'horizontal')!http://chart.apis.google.com/chart?cht=bhs&chs=300x200&chd=s:9UGo(bars)! *pie chart*
Gchart.pie(:data => [20, 35, 45])!http://chart.apis.google.com/chart?cht=p&chs=300x200&chd=s:bv9(Pie Chart)! *venn diagram* "Google documentation":http://code.google.com/apis/chart/#venn Data set: * the first three values specify the relative sizes of three circles, A, B, and C * the fourth value specifies the area of A intersecting B * the fifth value specifies the area of B intersecting C * the sixth value specifies the area of C intersecting A * the seventh value specifies the area of A intersecting B intersecting C
Gchart.venn(:data => [100, 80, 60, 30, 30, 30, 10])!http://chart.apis.google.com/chart?cht=v&chs=300x200&chd=s:9wkSSSG(Venn)! *scatter plot* "Google Documentation":http://code.google.com/apis/chart/#scatter_plot Supply two data sets, the first data set specifies x coordinates, the second set specifies y coordinates, the third set the data point size.
Gchart.scatter(:data => [[1, 2, 3, 4, 5], [1, 2, 3, 4 ,5], [5, 4, 3, 2, 1]])!http://chart.apis.google.com/chart?cht=s&chs=300x200&chd=s:MYkw9,MYkw9,9wkYM(scatter)! --- *set a chart title*
Gchart.bar(:title => "Recent Chart Sexyness", :data => [15, 30, 10, 20, 100, 20, 40, 100])!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(chart title)! *set the image background color*
Gchart.bar( :title => "Matt's Mojo", :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], :background => 'EEEEEE')!http://chart.apis.google.com/chart?chf=bg,s,EEEEEE&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(Background)! *set the chart background color*
Gchart.bar( :title => "Matt's Mojo", :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], :background => 'EEEEEE', :chart_background => '000000')!http://chart.apis.google.com/chart?chf=c,s,000000|bg,s,EEEEEE&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(chart background)! h2. Repository The trunk repository is
svn://rubyforge.org/var/svn/Gchart/trunk
for anonymous access.
h2. License
This code is free to use under the terms of the MIT license.
h2. Contact
Comments are welcome. Send an email to "Matt Aimonetti":mailto:mattaimonetti@gmail.com