vis.js playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.9.0/vis.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.9.0/vis.min.css">
123
<div id="mynetwork"></div>
CSS
#mynetwork {
width: 500px;
height: 500px;
border: 1px solid lightgray;
}
JavaScript
// create an array with nodes
var nodes = [
{"id":"1","fixed":{"x":true,"y":true},"x":0,"y":-200,"label":"1"},
{"id":"2","fixed":{"x":true,"y":true},"x":0,"y":200,"label":"2"},
{"id":"3","label":"3"},
{"id":"4","label":"4"},
{"id":"5","label":"5"},
{"id":"6","label":"6"}
];
var edges = [{"from":"1","to":"3"},{"from":"2","to":"4"},{"from":"2","to":"5"},{"from":"2","to":"6"},{"from":"3","to":"5"},{"from":"3","to":"6"}];
// create a network
var container = document.getElementById('mynetwork');
// create a visJS dataSet
var nodesObj = new vis.DataSet( nodes );
var edgesObj = new vis.DataSet( edges );
// provide the data in the vis format
var data = {
nodes: nodesObj,
edges: edgesObj
};
var options = {
width: "500px",height:"500px",
interaction: {
dragNodes: true,// do not allow dragging nodes
zoomView: false, // do not allow zooming
dragView: false // do not allow dragging
},
};
// initialize your network!
var network = new vis.Network(container, data, options);
network.moveTo({
position: {x:0,y:0},
scale: 1.0,
offset: {x:0,y:0}
})
network.on('afterDrawing', function(){
let data = [{id: 1, x: 0, y:-200}, {id:2, x:0, y:200}];
nodesObj.update(data);
})