我正在使用d3.js ad force布局,但我有这个问题: TypeError: c.target是未定义的,我知道这是什么,以及如何删除它,但我不想
d3.json("myfile.json", function(graph) {
var nodeMap = {};
graph.nodes.forEach(function(d) { nodeMap[d.name] = d; });
graph.links = graph.links.map(function(d) {
return {
source: nodeMap[d.source] ,
target: nodeMap[d.target] ,
value: d.value
};
});
force
.nodes(graph.nodes)
.links(graph.links)
.on("tick", tick)
.start();这是我用来加载json数据和构建图形的代码。
if i put ( || 0 )in :
source: nodeMap[d.source] || 0,
target: nodeMap[d.target] ||0,这会破坏代码,并且不会为“d”节点绘制链接。相反,我想要跳转到相同"d“节点的下一个c.target的类似"continue语句”的语句。
有人能帮帮我吗?
发布于 2013-12-10 04:24:13
您可以过滤掉引用不存在的节点的链接:
graph.links = graph.links.filter(function(d) {
return nodeMap[d.source] && nodeMap[d.target];
}).map(function(d) {
return {
source: nodeMap[d.source] ,
target: nodeMap[d.target]
};
});https://stackoverflow.com/questions/20472348
复制相似问题