I'm just starting with d3.js and have copied the example for d3.js v3 and trying to adapt it for v4. I have the following part of code:
var width = 960,
height = 500,
fill = d3.schemeCategory20;
// another code
var force = d3.forceSimulation()
.size([width, height]) // the error occurred at this row
.nodes([{}])
.linkDistance(50)
.charge(-200)
.on("tick", tick);
d3.forceSimulation() is an operator of v4, so my question is: "How should I use all of the following operators with new d3.forceSimulation() syntax of version 4 of d3.js"?
Thanks in advance
Simply because size() is not a simulation object method
see the docs for more info
As per this issue, you can try to use the forceX/Y forces as below:
var force = d3.forceSimulation()
.size([width, height]) // the error occurred at this row
.nodes([{}])
.linkDistance(50)
.charge(-200)
.force("x", d3.forceX([width/2]).strength(0.01))
.force("y", d3.forceY([height/2]).strength(0.01))
.on("tick", tick);
You can play with the strength parameter to control how much spread out your graph is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With