这是一种简单的方法:
var edges = [];json.links.forEach(function(e) { var sourceNode = json.Nodes.filter(function(n) { return n.Id === e.Source; })[0], targetNode = json.Nodes.filter(function(n) { return n.Id === e.Target; })[0]; edges.push({ source: sourceNode, target: targetNode, value: e.Value });});force .nodes(json.Nodes) .links(edges) .start();var link = svg.selectAll(".link") .data(edges) ...这是工作中的PLUNK。(为了安全起见,您应该分叉它,以防万一我无意中删除了它。)



