问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/58043375/how-do-i-redraw-an-rgraph-svg-line-plot