在研究下面示例中的代码时,我想我几乎得到了一切
除非我一生都无法看到tick()如何继续被调用。(意思是,当该函数继续运行并因此继续更新图表时。
tick 不会被调用,也没有 setinterval 或类似的东西。我也不明白 .each("end", tick) 的作用。有人可以建议吗?这是使用 d3.js
tick();
function tick() {
// push a new data point onto the back
data.push(random());
// redraw the line, and slide it to the left
path
.attr("d", line)
.attr("transform", null)
.transition()
.duration(500)
.ease("linear")
.attr("transform", "translate(" + x(-1) + ",0)")
.each("end", tick);
// pop the old data point off the front
data.shift();
}
最佳答案
您感到困惑的两件事是有联系的。 #each用于处理转换事件。一个例子是 end
事件,在转换完成后触发。此代码表示“转换完成后(即触发 end
事件时),调用 tick
。这将启动新的转换,并且将重复相同的操作,调用再次勾选
。
关于javascript - 无法理解为什么函数不断在 d3.js 上被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37476128/