我正在用d3.js ad force布局,但我遇到这个问题: TypeError:c.target未定义,我知道这是什么,以及如何删除它,但我不想d3.js继续条件加载数据
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。
有人可以帮助我
这不是我清楚你的要求。你想知道如何跳过没有定义目标的链接吗? –
做一个jsfiddle和分享...这将有助于帮助 – sam
是的。例如 节点:[{名称:A},{名称:B}],链接:[{source:A,target:B},[source:A,target:C]] 在这种情况下,代码报告错误c.target未定义,但我只想要A-B交互 – andrea