![](/img/trans.png)
[英]this.setAttribute is not a function when using D3's .attr method
[英]d3 v4 error this.setAttribute is not a function
我试图将以下示例转换为d3 v4兼容http://bl.ocks.org/ameyms/9184728
我已经能够转换几乎所有的,但我遇到以下功能的问题:
this.el.transition().delay(100).duration(200).select('.needle').tween('reset-progress', function() {
return function(percentOfPercent) {
var progress = (1 - percentOfPercent) * oldValue;
repaintGauge(progress);
return d3.select(this).attr('d', recalcPointerPos.call(self, progress));
};
});
我得到的错误是this.setAttribute is not a function
返回行this.setAttribute is not a function
。 我已经验证了recalcPointerPos
正常工作,所以我认为问题在于d3.select(this).attr语法。 v3和v4之间的这种选择有什么变化吗?
小提琴: https : //jsfiddle.net/v1tok1k6/
内部返回选择有错误的this
范围内选择的元素。 你想要的是外部函数this
,它代表了path
元素。 我在外部作用域上进行选择以进行缓存。
this.el.transition().delay(300).duration(1500).select('.needle').tween('progress', function(d, i, e) {
var needle = d3.select(this);
return function(percentOfPercent) {
var progress = percentOfPercent * perc;
repaintGauge(progress);
return needle.attr('d', recalcPointerPos.call(self, progress));
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.