使用vis.js
function draw() {
destroy();
nodes = [];
edges = [];
var model = { "nodes": [{ "id": 1, "label": "1. First", "level": 0 }, { "id": 2, "label": "2. Second", "level": 1 }, { "id": 3, "label": "3. Third.", "level": 2 }, { "id": 4, "label": "4. Forth", "level": 3 }, { "id": 5, "label": "5. Fith", "level": 4 }], "edges": [{ "from": 1, "to": 2 }, { "from": 2, "to": 3 }, { "from": 3, "to": 4 }, { "from": 4, "to": 5 }, { "from": 2, "to": 4 }] };
nodes = model.nodes;
edges = model.edges;
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
layout: {
hierarchical: {
direction: "UD"
}
}
};
network = new vis.Network(container, data, options);
}
这是我期望的:
但是我却得到了:
“ 3”位于中间,其边缘重叠2到4。
方向很重要1必须在顶部,5在底部。
任何建议如何防止这种重叠?