我无法编译 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); // < !!!!!-------
Run Code Online (Sandbox Code Playgroud)
我收到错误;
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.
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办,因为 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;
Run Code Online (Sandbox Code Playgroud)
声明文件中有一部分。
这有效。将带有数据的线生成器立即设置为属性。
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));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2125 次 |
| 最近记录: |