Alex Rivera | Logout

Simplest way to clear a container using raphaeljs javascript graphical library

Asked 2009-07-12T14:44:36.713
12

I have to clear and redraw a raphael javascript main container. I've tried with

var paper = Raphael(10, 50, 320, 200);
paper.remove();  // Doesn't work
paper.node.removeNode();    //this neither
paper.removeNode();   //this neither

Any idea?

Edit
Report

2 Answers

15

When you create a paper it creates a DOM object. You can access this with

paper.canvas

When you create a new Raphael object, you create a new DOM object and leave the original one alone! This is the best way to do it considering everything though. If you want to delete the canvas you only need to do the next command:

//Note: after calling this function the paper object will be useless!
//Make paper object null (or a new paper object) immediately!
function clearPaper(paper){
    var paperDom = paper.canvas;
    paperDom.parentNode.removeChild(paperDom);
}
answered 2009-08-27T04:18:04.580
3

with the latest gRaphael 0.5.1, I clear the chart easily with just calling the clear() method. i.e.

var r = Raphael(...)
r.clear();

But I'm not sure if it would work for your version

answered 2012-09-23T12:49:43.187

Your Answer