//只有数据比line对象多的时候,才执行enter
center.enter().append("line")
.attr("class", "center")
.attr("x1", width / 2)
// 每次都要执行
center
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1])+1; });
// 只有line对象比数据多的时候,才进行调用
center.exit()
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1])+1; })
.remove();
- selection.enter - 返回缺失元素的占位对象(placeholder),指向绑定的数据中比选定元素集多出的一部分元素。
- selection.exit - 返回多余元素的元素集,即选择元素中比绑定数据多出的一部分。(关于data, enter, exit原理的示例1, 示例2, 示例3)