ruport で svg グラフを生成
ruport という 表生成のライブラリーを試してみた。( http://rubyreports.org/ )
# xfy/xvcd からの ruby 呼び出しで、ruport をつかって readonly の表
# を生成させようと企んでいるところ。
# html, text, svg, pdf の書式で表を生成できるところが魅了的だ...
rubygems で install したのは次のバージョン:
ruport (1.0.1)
A generalized Ruby report generation and templating engine.
ruport-util (0.7.2)
A set of tools and helper libs for Ruby Reports
http://rubyreports.org/examples.html にあるサンプルを試す。
SVG Graphs with ruport-util として、 svg 出力の例がある。
日本語を試すが、文字化けする。(firefox での表示)
試しに firefox でなく、xfy (1.5) や safari で表示させてみた。
おお! 日本語が表示された。
でも xfy はグラフの縦軸ラベルの表示位置がずれてるなぁ。orz...
以下に ruby コードと、生成されたsvg を示す。
# See http://rubyreports.org/examples.html
require "rubygems"
require "ruport"
require "ruport/util"$KCODE = 'utf-8'
class GraphReport < Ruport::Report
renders_as_graph
def GraphReport::setData(column, lines)
@@column = column
@@lines = lines
enddef generate
graph = Ruport::Graph(:column_names => @@column)
@@lines.each {|key, val|
graph.add_line val, :name => key
}
return graph
end
endoutname = "foo.svg"
column = %w[a b c d e];
lines = {"あいう"=>[1,2,3,4,5], "bar"=>[11,22,70,2,19]}GraphReport.setData(column, lines)
GraphReport.generate {|r| r.save_as(outname)}
« ピックアップ:日曜の夜はペルセウス座流星群のピーク, ブラウザ上で翻訳ファイルが編集できるソフト, etc... | トップページ | ピックアップ:Gmailの容量が最大250GBまで拡張可能, 新入生に学生生活をブログで公開させる大学, etc... »
この記事へのコメントは終了しました。
« ピックアップ:日曜の夜はペルセウス座流星群のピーク, ブラウザ上で翻訳ファイルが編集できるソフト, etc... | トップページ | ピックアップ:Gmailの容量が最大250GBまで拡張可能, 新入生に学生生活をブログで公開させる大学, etc... »
コメント