【发布时间】:2016-01-22 07:15:32
【问题描述】:
我正在尝试将我的可视化脚本更改为更像Modifying a Force Layout Example。因为我没有像a, b and c 这样的固定节点要添加,所以我读取了json file 来填充nodes 和links 数组。
d3.json("mock.json", function(error, json) {
if (error)
throw error;
nodes = nodes.concat(json.nodes);
links = links.concat(json.links);
start();
});
nodes 和 links 具有正确的大小,这意味着节点包含 26 nodes 和链接 37 links。现在我想使用line 和circle 元素简单地可视化它们。
function start() {
link = link.data(force.links(), function(d) { return d.source.id + "-" + d.target.id; });
link.enter().append("line").attr("class", "link");
link.exit().remove();
node = node.data(force.nodes(), function(d) { return d.id;});
node.enter().append("circle").attr("class", "node").attr("r", 8);
node.exit().remove();
force.start();
}
这与示例非常相似,我真的不明白为什么这不起作用。我向a demo 提供模拟。是否因为我使用concat() 而不是push() 而出现问题,还是有其他问题?
【问题讨论】:
标签: javascript json d3.js force-layout