使用JSXGraph时如何删除创建的点?

时间:2019-06-15 15:17:36

标签: javascript jsxgraph

最近我正在研究算法gameOfLife。

我发现JSXGraph非常方便和有用。我只需要包括这些库并添加几行即可绘制,如下面的最小示例所示。

<!DOCTYPE html>
<html>
<head>
    <title>Ultimate Slot Machine</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
    <script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>

</head>
<body>
    <div id="box" class="jxgbox" style="width:800px; height:800px; margin: 0 auto;"></div>
    <script type="text/javascript">
     var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-10, 10, 10, -10], axis:false, grid:true});

     var p = board.create('point',[-3,1]);

     var q = board.create('point',[-3,1], {face:'x', size:16});
    </script>

</body>
</html>

问题是我不知道如何删除创建的点,并且在官方文档中找不到任何参考。

https://jsxgraph.org/docs/symbols/Point.html

https://jsxgraph.org/wiki/index.php/Point

请帮助。

1 个答案:

答案 0 :(得分:0)

通过调用board.removeObject(object);board.removeObject([array of objects]);来删除

JSXGraph元素。您的示例如下所示:

 var p = board.create('point',[-3,1]);
 var q = board.create('point',[-3,1], {face:'x', size:16});
 board.removeObject(p);
 board.removeObject(q);
 // or
 board.removeObject([p, q]);