Over a million developers have joined DZone.

View A Dynamic Graph In A FXruby Application

·


require 'rubygems'
require 'fox16'
require 'gruff'

include Fox

application = FXApp.new("View", "")
main = FXMainWindow.new(application, "View", :opts=>DECOR_ALL,:width => 800, :height => 600)

graph = Gruff::Line.new
graph.title = "My Graph" 
graph.data("Apples", [1, 2, 3, 4, 4, 3])
graph.data("Oranges", [4, 8, 7, 9, 8, 9])
graph.data("Watermelon", [2, 3, 1, 5, 6, 8])
graph.data("Peaches", [9, 9, 10, 8, 7, 9])
graph.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
blob=graph.to_blob

graphImage = FXPNGImage.new(application, blob)
graphImage.create

imagesCanvas = FXCanvas.new(main, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y)
imagesCanvas.connect(SEL_PAINT) do |canvas, sel, ev|
  dc = FXDCWindow.new(canvas, ev)
  dc.drawImage(graphImage, 0, 0)
end

application.create()
main.show(PLACEMENT_SCREEN)
application.run()

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}