我需要在 JSON 对象中显示一系列数据存储。我必须在流程图中显示它,这基本上是一棵树,每个节点只有一个子节点。这是我的代码,试图实现集群布局。
//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(”+dy+“,”+dx+“)”来调整它们的位置。当我使用更简单的 JSON 对象时,这个问题从未发生过。谁能解释为什么自填充的协调器具有无效值?我的 JSON 对象有什么问题吗?