简体   繁体   English

.delay()不是d3中的函数

[英].delay() is not a function in d3

So far the only library I have imported is d3, and I checked the d3.js file to make sure the function was there. 到目前为止,我导入的唯一库是d3,并且我检查了d3.js文件以确保该功能在那里。 It was. 它是。

I'm trying to do the example from the data visualization with D3 and AngularJS book. 我正在尝试使用D3和AngularJS进行数据可视化示例。 Here's the code [directly from the book, with comments removed] in question: 这是有问题的代码(直接从书中删除注释):

<svg width="800" height="500"></svg>
<script type="text/javascript">
var data = [];
setInterval(function(){
    if (data.length < 8) {
        data.push(Math.random());
    }
    else {
        data = [];
    }
    draw();
}, 1000);

function draw() {
    var svg = d3.select('svg');

    var circles = svg.selectAll('circle').data(data);

    circles
    .attr('fill', 'orange');

    circles.enter()
    .append('circle')
    .attr('fill', 'red')
    .attr('r', 40)
    .attr('cx', function(d, i) { return i*100 + 50; })
    .attr('cy', 50);

    circles
    .style('stroke', 'black');

    circles.exit()
    .delay()
    .remove();
}

The problem I am having specifically is at 我具体遇到的问题是

circles
.exit()
.delay()
.remove();

It says that the delay function "is not a function" even though it is. 它说延迟函数“不是函数”,即使它是。 I tried porting the code exactly from the book into a completely new project, but it doesn't work. 我尝试将代码完全从书中移植到一个全新的项目中,但是它不起作用。 (I'm using the chrome browser if that makes a difference). (如果使用Chrome浏览器,那会有所作为)。

Thanks 谢谢

delay() is not a function of selections . delay()不是selections的函数。 You can call delay() for transitions, however. 但是,您可以调用delay()进行转换。 So : 因此:

circles
  .exit()
  .transition()
  .delay()
  .remove();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM