我是JSNetworkX的新手。我使用 jsnetworkx.org 示例中的示例创建了一个图表,但我只能记录它,无法显示它。
所以这是index.html
文件:
<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>
这是用script.js
编写的代码:
var G = jsnx.completeGraph(6);
console.log(G.nodes());
jsnx.draw(G, {
element: 'body',
weighted: true,
edgeStyle: {
'stroke-width': 10
}
});
这是输出:[0, 1, 2, 3, 4, 5]
这是我得到的错误:
JSNetworkX 错误 - TypeError: undefined 不是对象(正在评估"M.layout.force")
问题在于包含最新版本的 D3.js。
改变
<script src="https://d3js.org/d3.v4.js"></script>
自
<script src="https://d3js.org/d3.v3.js"></script>
会修复它。