image

  • フォト Amazonギフト券
    ※この時計の時刻は、閲覧しているパソコンのものであり、必ずしも正確な時間とは限りません

検索

最近のトラックバック

無料ブログはココログ

« ピックアップ:ODFのRELAX NGスキーマの欠陥, Rubyによる多次元配列の実装方法について, etc... | トップページ | ピックアップ:「平八」的なものについて, 日本はピラミッド建設に乗り出したらどうか, etc... »

2008-05-07

google chart api のサンプル

- http://gchartrb.rubyforge.org/
> gchartrb is a Ruby wrapper around the Google Chart API, located at code.google.com/apis/chart/
というものがあるのを知った。

これは http://code.google.com/intl/ja/apis/chart/ を ruby から使うための wrapper だ。

rdoc 中のサンプルコードをまとめて走らせてみた。
出力結果は、各グラフ生成要求の url だ。

$ cat sample00.rb
# See http://gchartrb.rubyforge.org/

require 'rubygems'
require 'google_chart'

# ---------------------
bc = GoogleChart::BarChart.new('800x200', "Bar Chart", :vertical, false)
bc.data "Trend 1", [5,4,3,1,3,5], '0000ff'

# Fill Area (Multiple Datasets)
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
lc.show_legend = false
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
lc.data "Trend 2", [3,3,4,3,3], '00ff00'
lc.data "Trend 3", [1,1,2,1,1], '0000ff'
lc.data "Trend 4", [0,0,0,0,0], 'ffffff'
lc.fill_area '0000ff',2,3
lc.fill_area '00ff00',1,2
lc.fill_area 'ff0000',0,1
end
puts lc.to_url
puts

# Fill Area (Single Dataset)
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
lc.show_legend = false
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
lc.fill_area 'cc6633', 0, 0
end
puts lc.to_url
puts

# ---------------------
flc = GoogleChart::FinancialLineChart.new do |chart|
chart.data "", [3,10,20,37,40,25,68,75,89,99], "ff0000"
end
puts flc.to_url
puts

# ---------------------
# Line Chart
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center
lc.axis :x, :range => [0,6], :color => '00ffff', :font_size => 16, :alignment => :center

# Line XY Chart
lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true)
lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff'
lcxy.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], '00ff00'
puts lcxy.to_url
puts

# ---------------------
pc = GoogleChart::PieChart.new("600x300", "Food and Drinks Consumed Christmas 2007")
pc.data "Egg nog", 10, '00AF33'
pc.data "Christmas Ham", 20, '4BB74C'
pc.data "Milk (not including egg nog)", 8, 'EE2C2C'
pc.data "Cookies", 25, 'CC3232'
pc.data "Roasted Chestnuts", 5, '33FF33'
pc.data "Chocolate", 3, '66FF66'
pc.data "Various Other Beverages", 15, '9AFF9A'
pc.data "Various Other Foods", 9, 'C1FFC1'
pc.data "Snacks", 5, 'CCFFCC'
puts pc.to_url
puts

# ---------------------
sc = GoogleChart::ScatterChart.new('320x200',"Scatter Chart")
sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
sc.point_sizes [10,15,30,55]
puts sc.to_url
puts

# ---------------------
vd = GoogleChart::VennDiagram.new("320x200", 'Venn Diagram')
vd.data "Blue", 100, '0000ff'
vd.data "Green", 80, '00ff00'
vd.data "Red", 60, 'ff0000'
vd.intersections 30,30,30,10
puts vd.to_url
puts

ruby でも、jruby でも動作する。ここでは jruby で走らせてみた。
$ jruby sample00.rb
http://chart.apis.google.com/chart?chs=320x200&cht=lc&chco=ff0000,00ff00,0000ff,ffffff&chd=s:yy9yy,eeoee,KKUKK,AAAAA&chm=b,0000ff,2,3,0|b,00ff00,1,2,0|b,ff0000,0,1,0&chtt=Line+Chart

http://chart.apis.google.com/chart?chs=320x200&cht=lc&chco=ff0000&chd=s:yy9yy&chm=B,cc6633,0,0,0&chtt=Line+Chart

http://chart.apis.google.com/chart?chs=100x15&cht=lfi&chco=ff0000&chd=s:BGMWYPpu29

http://chart.apis.google.com/chart?chs=320x200&cht=lxy&chco=0000ff,00ff00&chd=s:Pet9,MYkw,9ePt,9YMw&chdl=Trend+1|Trend+2&chtt=Line+XY+Chart

http://chart.apis.google.com/chart?chs=600x300&cht=p&chco=00af33,4bb74c,ee2c2c,cc3232,33ff33,66ff66,9aff9a,c1ffc1,ccffcc&chd=s:YwT9MHkVM&chl=Egg+nog|Christmas+Ham|Milk+(not+including+egg+nog)|Cookies|Roasted+Chestnuts|Chocolate|Various+Other+Beverages|Various+Other+Foods|Snacks&chtt=Food+and+Drinks+Consumed+Christmas+2007

http://chart.apis.google.com/chart?chs=320x200&cht=s&chd=s:Pet9,Pet9,LQh9&chtt=Scatter+Chart

http://chart.apis.google.com/chart?chs=320x200&cht=v&chco=0000ff,00ff00,ff0000&chd=s:9wkSSSG&chdl=Blue|Green|Red&chtt=Venn+Diagram

この blog に引用した 出力 URL には hyperlink を張っておいた。
クリックすると生成されたグラフが瞬時に表示される。

最後のベン図のイメージだけはスクリンショットを示そう。

Ven


出力形式をSVG にしたような類似サービス or API が xfy にもあるとよいと思う。

« ピックアップ:ODFのRELAX NGスキーマの欠陥, Rubyによる多次元配列の実装方法について, etc... | トップページ | ピックアップ:「平八」的なものについて, 日本はピラミッド建設に乗り出したらどうか, etc... »

コメント

この記事へのコメントは終了しました。

トラックバック


この記事へのトラックバック一覧です: google chart api のサンプル:

» Recent Links Tagged With Barchart [JabberTags - Find New Sites and Explore the Internet]
Bookmarked your site as barchart at JabberTags! [続きを読む]

« ピックアップ:ODFのRELAX NGスキーマの欠陥, Rubyによる多次元配列の実装方法について, etc... | トップページ | ピックアップ:「平八」的なものについて, 日本はピラミッド建設に乗り出したらどうか, etc... »

mokuji

2013年12月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

google

  • twitter
  • __
  • _
    Googleボットチェッカー

合わせて読む

  • 合わせて読む
    フィードメーター - katoy: cocolog あわせて読みたい

リンク