Json D3.js集群布局中填充的x/y属性的NaN值
我需要在JSON对象中显示一系列数据存储。我必须在流程图中显示它,它基本上是一棵树,每个节点只有一个子节点。 这是我的代码,试图实现集群布局Json D3.js集群布局中填充的x/y属性的NaN值,json,entity-framework,d3.js,hierarchy,Json,Entity Framework,D3.js,Hierarchy,我需要在JSON对象中显示一系列数据存储。我必须在流程图中显示它,它基本上是一棵树,每个节点只有一个子节点。 这是我的代码,试图实现集群布局 //JSON object var tmp = { "clusternum":1, "res":["linklinklink"], "cour":["Test Manager","Introduction to Building a Case"], "comp":[], "ex":["none"], "chi
//JSON object
var tmp = {
"clusternum":1,
"res":["linklinklink"],
"cour":["Test Manager","Introduction to Building a Case"],
"comp":[],
"ex":["none"],
"children":[{
"clusternum":2,
"res":["fafafa"],
"cour":["PLS ASTD Conference"],
"comp":[],
"ex":["none"],
"children":[{
"clusternum":3,
"res":[],
"cour":["Excel Macros / VBA"],
"comp":[],
"ex":["none"],
"children":[{
"clusternum":4,
"res":[],
"cour":["none"],
"comp":[],
"ex":["Midterm"],
"children":[{
"clusternum":5,
"res":[],
"cour":["Project Management Training"],
"comp":[],
"ex":["none"],
"children":[{
"clusternum":6,
"res":[],
"cour":["Test Management","/learn Blaine Whittle"],
"comp":[],
"ex":["none"],
"children":[{
"clusternum":7,
"res":[],
"cour":["none"],
"comp":[],
"ex":["Final"],
"children":[""]
}]
}]
}]
}]
}]
}]}
var nodes = clusterlayout.nodes(tmp);
links = clusterlayout.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter()
.append("g")
.attr("class", "node")
.attr("transform", function (d) { console.log(d);return "translate(" + d.y + "," + d.x + ")"; })
.on("click", function (d) { d3.select(this).attr("class", "node nodeineffect"); return zoom(d) });
在Firebug的控制台窗口中,我看到我的节点具有x=NaN和y=0属性,因此我无法使用“translate”(“+d.y+”,“+d.x+”)来调整它们的位置。这个问题以前在我使用更简单的JSON对象时从未发生过。有人能解释为什么自填充的协调器具有无效值吗?我的JSON对象有什么问题吗 刚才解决了。叶节点不应具有“children”属性。d3对JSON有一些非常奇怪的限制。那么你能回答你自己的问题吗?