javascript - D3 转换循环抛出 Uncaught TypeError : t. call is not a function

标签 javascript d3.js

对 D3 来说非常新,对 JS 通常来说相对较新。我试图在点击时创建一个圆圈,这个圆圈一旦创建就需要永远重复跳动。现在,它正在被正确地创建并且它进行了一次转换,但随后它由于错误而死亡。这是我的代码:

var shapesAtt = shapes
    // omitted: assigning fill, position, etc; working as intended
    .on("click", circleMouseClick);

function circleMouseClick(d, i)
{
    createPulse(this);
}

function createPulse(focusElement)
{
    // takes in "focal circle" element
    // some things here are hard coded for ease of reading 
    // (i.e. these variables aren't all useless)

    var focus = d3.select(focusElement);
    var origR = focus.attr("r");
    var origX = focus.attr("cx");
    var origY = focus.attr("cy");
    var origFill = focus.style("fill");

    var strokeColor = "black";

    var newG = svgContainer.append("g");
    var pulser = newG.append("circle").attr("id", "pulser")
        .style("fill", "none").style("stroke", strokeColor)
        .attr("cx", 150).attr("cy", 150)
        .attr("r", origR)
        .transition()
            .duration(2000)
            .each(pulsate);
}

function pulsate()
{
    var pulser = d3.select(this);
    pulser = pulser
        .transition().duration(2000)
            .attr("r", 25)
            .attr("stroke-width", 50)
        .transition().duration(2000)
            .attr("r", 90)
            .attr("stroke-width", 10)
        .each("end", pulsate);
}

我在 Chrome 中运行时收到的错误是:

Uncaught TypeError: t.call is not a function     d3.v4.min.js:4

我认为有问题的代码部分是:

function pulsate()
{
    // ...   
    .each("end", pulsate);
}

最佳答案

这是因为您使用的是 d3 version4。 v4 API 发生了重大变化,因此:

而不是使用

// ...   
.each("end", pulsate);//in d3 version 3

// ...   
.on("end", pulsate);//in d3 version 4

引用:https://github.com/d3/d3-transition#transition_on

关于javascript - D3 转换循环抛出 Uncaught TypeError : t. call is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38607647/

相关文章:

javascript - 与字典元素 typescript 进行比较

javascript - 在特定时间为视频添加链接

d3.js - 迭代 D3js 中已经创建的节点

javascript - 如何为plot.ly js图例着色以及为什么它是黑色的?

javascript 和 d3.js 变量范围 : variable resets outside of function call

javascript - 工具提示的 CSS 定位

javascript - javascript 变量过期?

javascript - nvd3 折线图未正确显示。 (点和阴影区域)

javascript - 为什么转换后旧条仍然可见

javascript - 为什么 onClick 会触发多次