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: 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!
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!
Share Improve this question asked Aug 8, 2016 at 2:03 dahliadahlia 2831 gold badge5 silver badges18 bronze badges 3- I am using a python simpleHTTPServer, is that what you mean by load the json? Or is there a step here that I am missing? – dahlia Commented Aug 8, 2016 at 2:39
- 1 Never mind, I have gotten it working. Something was wrong with the d3.js script that I had so I updated it and it's all fine. Sorry for the post. – dahlia Commented Aug 8, 2016 at 4:09
- @dahlia If this was just a minor glitch and after its correction is no longer reproducible, please consider deleting the question altogether. – altocumulus Commented Jan 17, 2017 at 17:47
4 Answers
Reset to default 15The 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
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.
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>
OK, since I'm already here and I had the same problem, my solution was to downgrade to //d3js.org/d3.v3.js