2

我正在尝试创建图形表示,但我不确定如何组织我的数据。

我目前将所有数据绑定到一个组并绘制了节点。

数据包括边列表,但我不确定如何绘制它们,因为每个节点都有不同数量的边。

var group = svg.selectAll("g").data(dataset).enter().append("g);

//this works

group.append("circle")
     .attr(...).attr(...).attr(...);

//what to do here? when I call group, it will loop through each node ONCE and append a path
//but I need it to append edges.length paths for each pass

group.append("path")
     .attr("d", function(d,i){

        //example of 1 line
        lineSeg = [];
        lineSeg.push({"x":d.x ,"y":d.y});
        lineSeg.push({"x":d.edges[1].x ,"y":d.edges[1].y});

        return line(lineSeg);

     });

编辑:

//just to add dom structure, my goal is for it to be:

g:
   circle
   path1
   path2

g:
   circle
   path1
   path2
   path3

g:
   circle
   path1

etc...

Lars 链接到相关教程页​​面。对我来说关键是嵌套数据连接

var td = d3.selectAll("tbody tr")
.data(matrix)
.selectAll("td")
.data(function(d, i) { return d; }); // d is matrix[i]
4

0 回答 0