[英]d3.js nested selection, doesn't work
So this is my code, I have an array of arrays, and they contain an object with 4 points, so I can draw a line using svg, when I tested the code using only an array it worked fine, but I can't make it work with an array of arrays, any help would be deeply appreciated. 所以这是我的代码,我有一个数组数组,并且它们包含一个有4个点的对象,因此当我仅使用数组测试代码时,我可以使用svg画一条线,但是效果很好,但是我无法它与数组数组一起工作,任何帮助将不胜感激。
var circle = svgContainer.selectAll("svg").data(mainMt);
console.log(circle);
console.log("Linea");
var line = circle.data(function(d) { return d; })
.enter().append("line")
.attr("x1", function (d) { return d.x1; })
.attr("y1", function (d) { return d.y1; })
.attr("x2", function (d) { return d.x2; })
.attr("y2", function (d) { return d.y2; })
.attr("stroke-width", 2)
.attr("stroke", "black");
console.log(line);
There are two things missing -- first, you need to operate on the enter selection of the top-level selection and second, select things for the nested selection: 缺少两件事–首先,您需要对顶级选择的回车选择进行操作,其次,为嵌套选择选择内容:
svgContainer
.selectAll("g.lines")
.data(mainMt)
.enter().append("g")
.attr("class", "lines")
.selectAll("line").data(function(d) { return d; })
.enter()
.append("line")
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.