I am new to d3.js and I am trying to learn by changing/looking at chunks of code.
I am running into the following issue: I get a Uncaught (in promise) TypeError: d3.forceSimulation is not a function
This is the line where I am getting the error:
const simulation = d3.forceSimulation(nodes)
// .force('charge', d3.forceManyBody().strength(5))
.force('x', d3.forceX().x(function(d) {
return xCenter[d.category]
}))
.force('y', d3.forceY().y(0))
.force('collision', d3.forceCollide().radius(d => 1.1*d.r*Math.sqrt(2)))
//.force('collision', collide)
.on('tick', ticked)
I have the following d3.js version loading in my html
: <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
If I load <script src="./../d3.v6.js"></script>
nothing will render. What might be the problem here?
CodePudding user response:
You should also include d3-force in your scripts.
<script src="https://cdn.jsdelivr.net/npm/d3-force@3"></script>