All the API examples seem to be for v3 still. I\'m trying to understand how to create a force graph with links of a fixed distance, like: http://bl.ocks.org/d3noob/5141278
You are closer to change the distance in v4! Check this change... it works for me:
var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d, i) { return i; }).distance(100).strength(1))
.force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2));
The original code was almost correct. However, the i
needs to be added to the function, and i
also needs to be returned in order to change the link distance. I edited the original code to reflect this. Please see this link: Link to Free Code Camp