dahlia
dahlia

Reputation: 283

Cannot read property 'force' of undefined (Simple D3 Network graph)

I am new to D3 and Javascript but have typically had luck with just copying the basic D3 scripts and getting my data into the proper format for the visualization to work. I have tried several of the D3 Network graphs and have gotten the same error for all of them when I inspect the page.

Uncaught TypeError: Cannot read property 'force' of undefined.

If you look at the script here: http://bl.ocks.org/jose187/4733747 I just copied it completely along with the respective .json file and am getting the above error. It seems to think that d3.layout.force() is an "anonymous function". Any ideas what is going on? Or how to fix it? Thank you!

Upvotes: 10

Views: 12337

Answers (4)

yadavankit
yadavankit

Reputation: 353

You will have to downgrade your D3 Version because version 3's d3.layout.force is now d3.layout.forceSimulation in version 4 as answered already.

Use this CDN for D3 Version 3 :

<script src="https://d3js.org/d3.v3.js"></script>

Upvotes: 2

Farshad Javadi
Farshad Javadi

Reputation: 419

The force layout d3.layout.force has been renamed to d3.forceSimulation in D3 V4 among many other changes.

Refer to this link for more information: D3 V4 Force

Upvotes: 15

tsadkan yitbarek
tsadkan yitbarek

Reputation: 1370

I have faced that problem too.The problem was the d3 version I was using which is version 4.When I use d3 version 3 it works properly.

Upvotes: 4

vladkras
vladkras

Reputation: 17228

OK, since I'm already here and I had the same problem, my solution was to downgrade to //d3js.org/d3.v3.js

Upvotes: 0

Related Questions