gpt4 book ai didi

typescript - D3 TypeScript 将元素设置为路径元素的属性

转载 作者:行者123 更新时间:2023-12-02 20:36:27 27 4
gpt4 key购买 nike

我无法编译 TypeScript 代码。

 var line = d3.line()
.x(function(d,i) {
return x(i);
})
.y(function(d) {
return y(d);
});

graph.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line); // < !!!!!-------

我收到错误;

Argument of type 'Line<[number, number]>' is not assignable to parameter of type 'ValueFn<BaseType, number[], string | number | boolean>'.
Types of parameters 'data' and 'datum' are incompatible.

我不知道该怎么办,因为类 Line 没有实现 ValueFn。我也没有看到这种情况的声明。

attr(name: string): string;
attr(name: string, value: null): this;
attr(name: string, value: string | number | boolean): this;

// element, in order, being passed the current datum (d),
attr(name: string, value: ValueFn<GElement, Datum, string | number | boolean | null>): this;

声明文件中有一部分。

最佳答案

这有效。将立即包含数据的行生成器设置为属性。

let lineGenerator = d3.line<ILineChartPoint>()
.x(function(d) { return x(d.x); })
.y(function(d) { return y(d.y); });
...
let line = g.append("path")
.attr("d", lineGenerator(this.data));

关于typescript - D3 TypeScript 将元素设置为路径元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46976677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com