I am having problems clearing the canvas when changing the Pie charts' data

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Preben on 15th December 2012
I whant to draw a pie with 3 parts and change that pie 'dynamically' everytime the user enter a new value in one of the parts textfield
The pie picks up the new data fine - but it stacks the new pie on top of the old one. I have tried with RGraph.ObjectRegistry.Clear() but then the canvas goes completly blank:

  var data = [var1,var2, var3]; //var1, var2, var3 from the textfield
         var pie = new RGraph.Pie('cvs', data);

Any suggestions how to clear the canvas so I just have one pie ? - thanks
Posted by RGraph support on 15th December 2012

You were close with RGraph.ObjectRegistry.Clear(), but that just clears the ObjectRegistry - what you want is this:


...which clears the canvas.

Richard, RGraph Support
Posted by sheenek on 15th December 2012
I´m facing similar issue.

I have one canvas in which i´m trying to draw line graphs. Draw one line graph, then erase and draw in the same canvas different one.

I´ve had partial success with redrawing Canvas the simple way - with white box. Looked fine when loaded graph. But the old graphs still seemed to remain there and showed themself when I clicked on the new graph, or when tooltip was showed. And I suddenly have had two (or more) graphs on top of each other. In other words strange behaviour.

So how do I use the RGraph.Clear()? When I use it without parameter it doesn´t do anything, should I pass to it a reference of some kind to my canvas?

Relevants part of my code here:

I do have latest version of rgraph (downloaded two weeks ago), and the issue is the same in every browser.

Thanks for response.
Posted by Preben on 16th December 2012
couldn't get the job done with RGraph.Clear (); but added a few other codelines instead:

// not in use RGraph.Clear(); use next two lines

     var canvas = document.getElementById('cvs');
    canvas.width = canvas.width;

   var data = [var1,var2, var3];
          var pie = new RGraph.Pie('cvs', data);

this clears the canvas and prevent pies from stacking up
see also remarks here: www.rgraph.net/canvas/docs/backwards-compatibility.html (under November 2012)
Posted by RGraph support on 16th December 2012

To use the .Clear function you needs to pass it a reference to your canvas, like this:

var canvas = document.getElementById('cvs');

The current stable version may have a small issue with anti-aliasing but the beta should be OK.
Posted by sheenek on 16th December 2012
Thanks for help, finally solved by using .Reset function and beta version, which seems to be working.

Clear function wasn´t sufficient, old graphs just reappeared just like before (when tooltip was shown, or clicked on graph), same with beta version.

Add a reply

« Back to message list