建议的解决方案是使用此映射功能:
var radialData = data.map(function(d) {
return {
source: {
x: 0,
y: 0
},
target: {
x: Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) - Math.PI,
y: Math.sqrt((d.target.x - d.source.x) * (d.target.x - d.source.x) + (d.target.y - d.source.y) * (d.target.y - d.source.y))
}
};
});
但是,所提供的解决方案似乎不适用于我的方法,因为 source.x 和 source.y 分配了 0。如何正确翻译源对象和目标对象,或者我是否遗漏了什么?
我的数据格式如下所示:
[{
source: {
x: -2.9799212566117377,
y: -221.97999925512298
},
target: {
x: -57.966610375613655,
y: -94.66188293902567
},
}, {
source: {
x: -20.132399189515613,
y: -221.08524713981706
},
target: {
x: -57.966610375613655,
y: -94.66188293902567
},
}]
另一种方法在:http://using-d3js.com/05_08_links.html 但是我不知道如何计算 xScale 和 yScale。
非常感谢任何帮助!先感谢您!