我在这里读过api,说x.strength和y.strength会设置引力的强度: https://github.com/d3/d3-force/blob/master/README.md#x_strength
但我该怎么申请?
simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function (d) {
return d.id;
}).distance(10))
.force("charge", d3.forceManyBody().strength(-15))
.force("center", d3.forceCenter(width * 0.5, height / 2))
答案 0 :(得分:9)
我在GitHub上快速搜索了一下:
https://github.com/search?l=JavaScript&q=forceX+strength&ref=searchresults&type=Code&utf8=%E2%9C%93
这看起来像正确的语法:
const forceX = d3.forceX(width / 2).strength(0.015)
const forceY = d3.forceY(height / 2).strength(0.015)
const simulation = d3.forceSimulation()
.force('x', forceX)
.force('y', forceY)