如何在 ruby 中显示 googlechart?
我想知道如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来
URI::parse
不喜欢 google 生成的 URL(可能是因为使用了|
)。因此在使用之前对其进行编码:It would appear that
URI::parse
does not like the URL google generate (probably because of the use of|
). So encode it before using: