我正在尝试使用Angularjs2组件中的d3绘制堆栈条形图(like this code)。以下行适用于Javascript:
var datasample="ethnicity,F Under 25,F Over 75,F 25 to 50,F 50 to 75,M Under 25,M Over 75,M 25 to 50,M 50 to 75\n"+
"Asian,327,296,332,309,306,330,307,323\n"+
"Black,294,302,330,305,295,363,322,292";
var data= this.d3.csvParse(datasample);
g.selectAll(".serie")
.data(d3.stack().keys(data.columns.slice(1))(data))
但是,当我在组件内的typescript中使用它时,我收到以下错误。
Argument of type 'DSVParsedArray<DSVRowString>' is not assignable to parameter of type '{ [key: string]: number; }[]'.
Types of property 'includes' are incompatible.
Type '(searchElement: DSVRowString, fromIndex?: number) => boolean' is not assignable to type '(searchElement: { [key: string]: number; }, fromIndex?: number) => boolean'.
Types of parameters 'searchElement' and 'searchElement' are incompatible.
Type '{ [key: string]: number; }' is not assignable to type 'DSVRowString'.
Index signatures are incompatible.
Type 'number' is not assignable to type 'string'.
我导入d3-ngservice以使用d3对象。
import { D3Service, D3, Selection } from 'd3-ng2-service';
似乎我应该以打字稿格式重写d3.stack()。keys行。有什么帮助吗?