【发布时间】:2021-04-23 13:26:57
【问题描述】:
我正在使用 D3.js、TypeScript 和 Vue Property Decorator 开发 Vue 项目。我想绘制热图,但是当我想调用 x() 或 y() 函数以返回热图中每个单元格的计算位置时出现错误。它抛出错误
类型“SVGAnimatedLength”没有调用签名。
这就是我初始化图表变量的方式
private svg: d3.Selection<SVGGElement, any, HTMLElement, any>
private x: d3.ScaleBand<string>
private xAxis: d3.Selection<SVGGElement, any, HTMLElement, any>
private y: d3.ScaleBand<string>
private yAxis: d3.Selection<SVGGElement, any, HTMLElement, any>
这是导致错误的地方
this.svg.selectAll()
.data(this.getData().filter((datum: HeatmapData) => this.betweenTwoDates(datum)))
.enter()
.append('rect')
.attr('x', function(d: HeatmapData) {
return this.x(d.dayNumber)
})
.attr('y', function(d: HeatmapData) {
return this.y(d.timeOfDay)
})
.attr('cx', 1)
.attr('cy', 1)
.attr('width', this.x.bandwidth())
.attr('height', this.y.bandwidth())
在
.attr('x', function(d: HeatmapData) {
return this.x(d.dayNumber)
})
错误发生在return this.x(d.dayNumber),声明Type "SVGAnimatedLength" has no call signatures。 .attr('y', ...) 也是如此。
this.x() 上的 this 的类型为 SVGRectElement。
【问题讨论】:
标签: javascript typescript d3.js