【问题标题】:How to make circle to appear one after another using d3 transition?如何使用d3过渡使圆圈一个接一个出现?
【发布时间】:2016-08-18 08:42:50
【问题描述】:

我在关注圈子example:

我创建了下面的圆圈,我希望使不透明度过渡成为随着数据集的更新,圆圈将开始一个接一个地出现。例如,如果数据长度为 5,则出现圆圈 1,然后出现圆圈 2,……最后出现圆圈 5。如果更新数据使其长度为 2,则出现圆圈 1,然后出现圆圈 2。我该如何做这个效果?到目前为止,transition() 统一地作用于数据集。

    circle.enter().append("circle")
        .attr("class", "dot");

    // Update (set the dynamic properties of the elements)
    circle
        .attr("r", 5)
        .attr("cy", 20)
        .attr("cx", function(d,i){return i*50;})
        .attr("fill", "red");

    svg.selectAll("circle")
        .style("opacity", 0)
        .transition()
        .duration(1000)
        .style("opacity", 1);

【问题讨论】:

    标签: javascript css d3.js css-transitions


    【解决方案1】:

    问题:

    为“过渡”选择中的每个元素设置延迟。

    解决方案:

    将delay() 与function(d, i) 一起使用

    说明:

    你必须在transition()之后添加这个:

    .delay(function(d,i){ return i * someNumber })
    

    其中 someNumber 是每个元素的延迟,以毫秒为单位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2012-11-12
      • 2013-12-02
      • 1970-01-01
      相关资源
      最近更新 更多