TypeError: undefined is not an object (evaluating 'M.layout.force')

孤街醉人 提交于 2019-12-25 07:22:05

问题


I'm new to JSNetworkX. I created a graph using the examples from jsnetworkx.org but I can only log it, I can't display it.

So this is index.html file:

<html>
<head>
  <script src="https://d3js.org/d3.v4.js"></script>
  <script src="jsnetworkx.js"></script>
</head>

<body>
  <script src = "script.js"></script>
</body>

</html>

And this the code written in script.js:

var G = jsnx.completeGraph(6);
console.log(G.nodes());
jsnx.draw(G, {
    element: 'body',
    weighted: true,
    edgeStyle: {
        'stroke-width': 10
    }
});

This is the output: [0, 1, 2, 3, 4, 5]

And this is the error i get:

JSNetworkX error - TypeError: undefined is not an object (evaluating 'M.layout.force')


回答1:


The problem was including the latest version of D3.js.

Changing

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

to

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

will fix it.



来源:https://stackoverflow.com/questions/38361472/typeerror-undefined-is-not-an-object-evaluating-m-layout-force

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!