Ruby:构建function图

在Ruby下构建函数图的最简单方法是什么? 有关特殊图形库的任何建议吗?

更新:仅在Windows下:-(

更新2:发现以下gem是目前为止的最佳解决方案https://github.com/clbustos/rubyvis

如果其他人偶然发现了这个问题,我可以使用以下代码使用gnuplot:

 require 'rubygems' require 'gnuplot' Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| plot.xrange "[-10:10]" plot.title "Sin Wave Example" plot.ylabel "x" plot.xlabel "sin(x)" plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" ds.linewidth = 4 end end end 

要求rubygems并使用正确的gem名称为gnuplot是我的关键。

这是我的首选图形库: SVG :: Graph

我真的很喜欢tioga 。 它可以在乳胶中生成令人难以置信的高质量,出版物就绪图。

使用SVG :: Graph :: Line像这样:

 require 'SVG/Graph/Line' fields = %w(Jan Feb Mar); data_sales_02 = [12, 45, 21] data_sales_03 = [15, 30, 40] graph = SVG::Graph::Line.new({ :height => 500, :width => 300, :fields => fields, }) graph.add_data({ :data => data_sales_02, :title => 'Sales 2002', }) graph.add_data({ :data => data_sales_03, :title => 'Sales 2003', }) print "Content-type: image/svg+xml\r\n\r\n"; print graph.burn(); 

有Microsoft Excel。

如果是这样, Ruby on Windows博客可能会有用,因为标记为win32ole和ruby的问题也是如此 。