Clearing canvas when changing data

Share RGraph:   To help my Google visibility (it can't get much worse!), if you like and use RGraph I'd appreciate it if you could link to me

« 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:

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

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

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

RGraph.Clear();

...which clears the canvas.

PS If you could link to the RGraph website I'd appreciate it - thanks.

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:
pastebin.com/C8qdXDX6

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);
          pie.Draw();

this clears the canvas and prevent pies from stacking up
see also remarks here: www.rgraph.net/libraries/.BC.txt (under November 2012)
Posted by RGraph support on 16th December 2012
Hi,

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

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

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