views:

8325

answers:

8

Any suggestion for a JS interactive drawing library? Just need to draw lines, polygons, texts of different colors. IE/Firefox/Opera/Safari compatible.

+5  A: 

You can use the canvas object directly to draw in 2D. IE requires the excanvas library.

http://developer.mozilla.org/En/Drawing_Graphics_with_Canvas

Craig B.
Canvas is the way to go for anything more than a few trivial boxes or lines. And excanvas works surprisingly well, at least on IE 7.
dgvid
Works great with IE6 too.
Prestaul
looks like Raphael can do more than simple boxes and lines.. http://raphaeljs.com/
ina
+8  A: 

John Resig's Processing.js is a nice framework for that.

Zach
how does processing.js compare with raphael for static graphics?
ina
Sadly Processing does not support IE. Thats a bit of a pity, it looks great though.
John Ballinger
+1  A: 

Depending on how cross-browser you need to be and your goal of doing the output, you might look into the Canvas element and the related javascript.

Canvas)

Steve g
+2  A: 

Try http://walterzorn.com/jsgraphics/jsgraphics_e.htm. It's the best I've found (without resorting to SVG) and works in most browsers without add-ins.

Steve Moyer
That stuff (drawing by arranging HTML elements) doesn't scale particularly well, but it certainly works :)
Dan
True ... you certainly wouldn't build a CAD system this way, but it can do pretty complex drawings if you stick with orthogonal structures and images (lines, rectangles, etc) and spice them up a bit with images. Other drawing entities are built with multiple DIV elements each.
Steve Moyer
+11  A: 

Raphael is pretty cool for that, and works across browsers since it uses VML (for MSIE) and SVG (for everything else).

Dan
Damn, you beat me to the punch ;)
Aeon
it doesn't support FF 2
THANKS heaps this looks super awesome. will be using Raphael.
John Ballinger
+2  A: 

Drawing text with the canvas tag is a big pain. Your options are to use regular divs absolutely positioned in the right places, or find/write a font layout engine (example), or wait for a new standard to be implemented that lets you draw text. SVG deals with this much better.

In IE you have ExplorerCanvas to simulate the canvas API with IE's own VML markup. However, native VML can do text on a path and such things much like SVG. I think theoretically if you want complex text handling you'd want SVG and VML like the Raphael library that Dan mentioned.

You might also consider Flash for a moment before starting.

jjrv
In fact, VML supports text drawing natively, and the latest revisions of ExplorerCanvas have the text drawing methods recommended by the WHATWG ;)http://explorercanvas.blogspot.com/
Fabien Ménager
+2  A: 

As mentioned above, canvas is the way you should go. IE doesn't support it natively, so you'll need to download ExCanvas to ensure cross-browser compatibility. I'd recommend looking at Ajaxian for some projects that use the canvas tag.

VirtuosiMedia
+1  A: 

Checkout the jQuery Drawing plugin, and you can also look at the Mozilla Canvas reference and tutorial.

CMS