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)
requ开发者_JS百科ire '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
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))
精彩评论