javascriptvis.jsvis.js-network

remove an edge in network vis.js


In vis.js, i can add easily an edge (ex function test) but i can't remove an existing edge (ex function test 1). Why ?

Unfortunately, i can't access now to documentation : "There isn't a GitHub Pages site here" for visjs.org. Thanks !

<input onclick=test() type="button" value="add edge 1 to 4 : ok">
<input onclick=test1() type="button" value="remove edge 1 to 2: not ok">

<div id="mynetwork"></div>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js"></script>

<script type="text/javascript">

    function test(){
        data.edges.add([{from: 1, to: 4}]);
    }

    function test1(){
        data.edges.remove([{from: 1, to: 2}]);
    }

    // GENERAL TEST
    var nodes = [
    {id: 1, label: 'Node 1'},
    {id: 2, label: 'Node 2'},
    {id: 3, label: 'Node 3'},
    {id: 4, label: 'Node 4'}
    ];

    var edges = [
    {from: 1, to: 2},
    {from: 1, to: 3},
    {from: 2, to: 4}
    ];

    nodesd = new vis.DataSet(nodes);
    edgesd = new vis.DataSet(edges);
    var container = document.getElementById('mynetwork');
    var data = {
        nodes: nodesd,
        edges: edgesd
    };

    var options = {
        nodes: {
            size:15
        },
        edges: {
            color: {
                inherit: "both"
            }
        }
    };
    network = new vis.Network(container, data, options);
</script>

Solution

  • It's ok now !

    I can do it with "id" for edges :

    var edges = [
    {id:1, from: 1, to: 2},
    {id:2, from: 1, to: 3},
    {id:3, from: 2, to: 4},
    {id:4, from: 2, to: 5}
    ];
    
    function test1(){
    data.edges.remove([1]);
    }