0

I have a simple web server embedded on a microcontroller. One of the web pages allows the user to plot captured data (in CSV format). The page first loads all of the data and presents it to the user, but then I want to allow the user to do things like select and deselect data (columns), change line colors and change data scales. When I naively call RGraph.SVG.Line a second time, it simply redraws the modified chart over top of the already existing image. How do I get RGraph to delete the previous image and start over?

I've tried the following (separately):

RGraph.Clear(document.getElementById("plotDiv"));
RGraph.ObjectRegistry.Clear();
document.getElementById("plotDiv").innerHTML="";

"RGraph.Clear" and "Graph.ObjectRegistry.Clear" don't appear to be available in the SVG version of the library. When I delete the div's "innerHTML", the div is cleared, but then RGraph.SVG.Line doesn't draw anything at all when it's called again.

Is there anything else that I can try?

Linda X
  • 44
  • 4

1 Answers1

2

You should call the clear function for SVG - not the canvas version:

RGraph.SVG.clear(myChart.svg);

To clear the registry (you may also need to do this):

RGraph.SVG.OR.objects = [];

You should then be able to draw a new chart on the SVG tag.

Richard
  • 4,809
  • 3
  • 27
  • 46
  • Thanks Richard. RGraph.SVG.clear seems to do the trick. I had only managed to track down the canvas API documentation. I have a better idea of what to look for now. – Linda X Sep 22 '19 at 01:32
  • I haven't written any SVG API documentation, but look through the RGraph.svg.common.core.js file to get an idea of what functions are available. – Richard Sep 22 '19 at 07:59