# SVG Canvas

**URL:** <https://www.ruby-forum.com/t/svg-canvas/79267>\
**Category:** Ruby\
**Created:** [December 13, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267 "2006-12-13T18:35:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/1 "2006-12-13T18:35:03Z")

</div>

I’ve been looking for a couple of days now and I can’t find a library  
for svg graphics with a canvas object so I can make a financial  
charting application(stand alone, not web based), is there such a  
thing? maybe I’m missing something obvious.  
Best regards,  
Steven

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/2 "2006-12-13T19:31:13Z")

</div>

Steven Quinones-Colon wrote:

> I’ve been looking for a couple of days now and I can’t find a library  
> for svg graphics with a canvas object so I can make a financial  
> charting application(stand alone, not web based), is there such a  
> thing? maybe I’m missing something obvious.

Most of the available GUI libraries support graphics. I have been using  
the  
Qt library for this sort of thing, and the graphics are quite  
acceptable:

[http://localhost/ruby/graphinity/index.html](http://localhost/ruby/graphinity/index.html)

[http://localhost/ruby/gravity/index.html](http://localhost/ruby/gravity/index.html)

I have only used the Qt library, there are several others, most of them  
offer this sort of graphic library. It’s not necessary to create a GUI  
in  
order to use the graphic libraries they offer.

If you were planning to create a GUI to go along with your graphic  
images,  
then this approach makes even more sense.

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/3 "2006-12-13T19:51:14Z")

</div>

On 12/13/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Steven Quinones-Colon wrote:
> 
> > I’ve been looking for a couple of days now and I can’t find a library  
> > for svg graphics with a canvas object so I can make a financial  
> > charting application(stand alone, not web based), is there such a  
> > thing? maybe I’m missing something obvious.
> 
> Most of the available GUI libraries support graphics. I have been using the  
> Qt library for this sort of thing, and the graphics are quite acceptable:  
> [snip]

> **[Graphinity: Graphing in Depth](https://arachnoid.com/ruby/graphinity/index.html)**
>
> A Ruby graphing and analysis program, recently rewritten.

> **[\* Modeling Gravity with Ruby](http://vww.arachnoid.com/ruby/gravity/index.html)**
>
> Ruby Gravitation. A Ruby program that models gravitation in real-time, as well as an article describing the physics of gravitation and computer modeling.

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/4 "2006-12-13T20:29:20Z")

</div>

On Dec 13, 2006, at 6:33 PM, Steven Quinones-Colon wrote:

> maybe I’m missing something obvious.  
> [RMagick 1.15.0: RVG Tutorial](http://www.simplesystems.org/RMagick/doc/rvgtut.html)

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/5 "2006-12-13T22:41:49Z")

</div>

Simon S. wrote:

> > acceptable:  
> > [snip]
> 
> [http://www.arachnoid.com/ruby/graphinity/index.html](http://www.arachnoid.com/ruby/graphinity/index.html)  
> [\* Modeling Gravity with Ruby](http://vww.arachnoid.com/ruby/gravity/index.html)

Thank you – I managed to overlook the URL content as I collected the  
data  
locally.

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 13, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/6 "2006-12-13T23:56:10Z")

</div>

On 14/12/2006, at 4:33 AM, Steven Quinones-Colon wrote:

> I’ve been looking for a couple of days now and I can’t find a library  
> for svg graphics with a canvas object so I can make a financial  
> charting application(stand alone, not web based), is there such a  
> thing? maybe I’m missing something obvious.  
> Best regards,  
> Steven

I haven’t tried it at all, but there are Ruby bindings for the Cairo  
library ([http://cairographics.org/rcairo](http://cairographics.org/rcairo)) which should produce really  
nice output.

Cheers,

Pete Y.

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 14, 2006, 12:29pm UTC](https://www.ruby-forum.com/t/svg-canvas/79267/7 "2006-12-14T12:29:28Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“SVG Canvas” on Thu, 14 Dec 2006 02:33:44 +0900,  
“Steven Quinones-Colon” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve been looking for a couple of days now and I can’t find a library  
> for svg graphics with a canvas object so I can make a financial  
> charting application(stand alone, not web based), is there such a  
> thing? maybe I’m missing something obvious.

If you want to only show SVG, the following example will  
help you:

[CVS Info for project ruby-gnome2](http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2/ruby-gnome2/rsvg/sample/svg-viewer.rb?revision=HEAD&view=markup)

If you want to output your chart to screen and SVG file, the  
following small script will help you:

====  
#!/usr/bin/env ruby

require ‘gtk2’  
require ‘rsvg2’

def draw(context, width, height)  
context.move\_to(0, 0)  
context.line\_to(width, height)  
context.stroke

context.move\_to(width, 0)  
context.line\_to(0, height)  
context.stroke  
end

window = Gtk::Window.new  
window.set\_default\_size(300, 300)  
vbox = Gtk::VBox.new  
area = Gtk::DrawingArea.new  
save = Gtk::Button.new(“save”)

window.signal\_connect(“destroy”) do  
Gtk.main\_quit  
end

area.signal\_connect(“expose\_event”) do |widget, event|  
width, height = area.window.size  
context = widget.window.create\_cairo\_context  
draw(context, width, height)  
true  
end

save.signal\_connect(“clicked”) do |widget, event|  
width, height = area.window.size  
surface = Cairo::SVGSurface.new(“output.svg”, width, height)  
context = Cairo::Context.new(surface)  
draw(context, width, height)  
context.show\_page  
surface.finish  
true  
end

vbox.pack\_start(area, true, true)  
vbox.pack\_end(save, false, false)  
window.add(vbox)  
window.show\_all

# Gtk.main

Thanks,

---

<div class="post-metadata">

**Author:** ![squinonescolon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@squinonescolon](https://www.ruby-forum.com/u/squinonescolon)\
**Post date:** [December 15, 2006, 1:21am UTC](https://www.ruby-forum.com/t/svg-canvas/79267/8 "2006-12-15T01:21:35Z")

</div>

Thanks, I’ll try these.  
Steven
