如何在 ruby​​ 中显示 googlechart?

发布于 2024-10-07 08:05:05 字数 817 浏览 1 评论 0原文

我想知道如何在 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

I was wondering how to display a chart made with gchartrb in ruby. I tried to do it by simply requiring the picture from the URL given but that gives the error "Bad URI". how do I do it? thanks

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2024-10-14 08:05:05

看起来 URI::parse 不喜欢 google 生成的 URL(可能是因为使用了 |)。因此在使用之前对其进行编码:

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

It would appear that URI::parse does not like the URL google generate (probably because of the use of |). So encode it before using:

@pic = Kernel.open(URI::encode($chart))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文