D3.js群集布局中填充的x / y属性的NaN值

时间:2013-07-02 23:43:46

标签: 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"],
    "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对象有什么问题吗?

0 个答案:

没有答案