我正在跟踪d3教程,同时对其进行调整以适应打字稿并做出反应,并且遇到attrTween问题
selection
.selectAll("rect")
.data(this.state.data)
.attr("x", d => this.x(d.name)!)
.attr("height", 0)
.attr("y", this.graphHeight)
.attr("width", this.x.bandwidth())
.attr("fill", "orange")
// .merge(selection.selectAll("rects"))
.transition()
.attrTween("width", this.widthTween)
.duration(500)
.ease(easeLinear)
.attr("y", d => this.y(d.orders))
.attr("height", d => this.graphHeight - this.y(d.orders));
在.attrTween("width", this.widthTween)
我无法将类型'(t:number)=>数字'分配给类型'(t:number)=>字符串'
这是widthTween
函数
widthTween = () => {
let i = interpolate(0, this.x.bandwidth());
return (t: number) => {
return i(t);
};
};
答案 0 :(得分:0)
我遇到了同样的问题,但是正如人们所说的,您应该强制您的补间函数返回一个字符串,您可以在attrTween
方法的重载中看到:
attrTween(name: string, factory: ValueFn<GElement, Datum, (t: number) => string>): this;