嗨,我正在尝试遵循这个示例,我使用硬编码的 json:
var json = {
"nodes":
[
{
"name": "Gosha",
"url": "www",
"center": true,
"group": 1
},
{
"name": "Vlad",
"url": "www",
"center": false,
"group": 1
},
{
"name": "Carmel",
"url": "www",
"center": false,
"group": 1
}
],
"links":
[
{
"source": "0",
"target": "1",
"weight": 0.5,
"value": 1
},
{
"source": "0",
"target": "2",
"weight": 0.6,
"value": 1
},
{
"source": "1",
"target": "2",
"weight": 0.8,
"value": 1
}
]
}
这是我的js代码:
var svg = d3.select("#sig").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.gravity(.05)
.distance(100)
.charge(-100)
.size([width, height]);
force
.nodes(json.nodes)
.links(json.links)
.start(); //error on this line
我有这个错误: Uncaught TypeError: Cannot call method 'push' of undefined
我认为问题与 json 有关(当我从示例中放入 json 时,它工作正常)。我试图验证我的 json - 它是有效的。
有任何想法吗?
谢谢,弗拉德