JSON オブジェクトに一連のデータ ストアを表示する必要があります。これをフローチャートで表示する必要があります。これは基本的に、ノードごとに子が 1 つだけあるツリーです。これが私のコードで、クラスターレイアウトを実装しようとしています。
//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 オブジェクトに何か問題がありますか?