我正在尝试使用d3js绘制图表(https://bl.ocks.org/mbostock/raw/4339083/)。这里是有问题的代码:因为崩溃是没有定义无法读取每个属性undefined - d3js
root.children.forEach(collapse);
和
d._children.forEach(collapse);
给予错误:
d3.json("/MyController/MyAction", function (error, flare) {
if (error) throw error;
console.log(flare);
root = flare;
root.x0 = height/2;
root.y0 = 0;
function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
}
root.children.forEach(collapse);
update(root);
});
的线条。我是否收到错误,因为我的JSON对象不正确?谢谢。
这里是我的控制台日志:
{"name":"Country","children":[{"name":"City","children":[{"name":"County","children":[{"name":"Child1","size":2},{"name":"Child2","size":2},{"name":"Child3","size":2}]}]}]}
你能告诉我有什么错呢?
你可以发布完整的工作示例,它给出错误吗?这段代码在我的控制台中正常工作 – bumbeishvili