首页 > 解决方案 > d3.js - enter() 序列中的空 selectAll() 没有效果?

问题描述

What is the effect of the initial selectAll(...)in a standard enter().append()sequence when the selection is empty? 似乎只有append有任何影响。例如:

index.html(删节)

<div id="example"></div>

脚本.js

var data = ["a", "b", "c"];

var vis = d3.select("#example");

vis.selectAll("foo")
    .data(data)
    .enter()
    .append("p")
    .text(function(d) { return d; });

创建

<div id="example">
  <p>a</p>
  <p>b</p>
  <p>c</p>
</div>

“富”去哪儿了?如果我们正在做一个空选择,那么我们输入的内容是否重要selectAll

例如,能够对selectAll(".foo").enter().append("p")所有 created<p>而不是 required进行分类可能会很好...append("p").attr("class", "foo")

我错过了什么吗?

标签: javascriptd3.js

解决方案


推荐阅读