如何在红宝石中显示googlechart?

时间:2010-12-11 20:55:15

标签: ruby url uri fxruby gchart

我想知道如何在ruby中显示用gchartrb制作的图表。我试图通过简单地要求给出URL中的图片来做到这一点,但这会给出错误“Bad URI”。我该怎么做?感谢

require 'rubygems'
require 'google_chart'





# Pie Chart
GoogleChart::PieChart.new('320x200', "Pie Chart",false) do |pc|
  pc.data "Apples", 40
  pc.data "Banana", 20
  pc.data "Peach", 30
  pc.data "darn", 600

  $chart = pc.to_url

end

require 'fox16'

include Fox

class Image_Viewer <FXMainWindow
  def initialize(app)
    super(app, "Image Viewer", :opts => DECOR_ALL, :width => 500, :height => 450)
    require 'open-uri'
    @pic = Kernel.open($chart, "rb")
    @pic2 = FXPNGImage.new(app, @pic.read)
    FXImageFrame.new(self, @pic2)

end
  def create
    super
    self.show(PLACEMENT_SCREEN)
end

end


app = FXApp.new
mainwin = Image_Viewer.new(app)

app.create
app.run

1 个答案:

答案 0 :(得分:0)

URI::parse似乎不喜欢Google生成的网址(可能是因为使用了|)。所以在使用之前对其进行编码:

@pic = Kernel.open(URI::encode($chart))