Javascript d3Service/d3-ng2-service TypeScript TS2346提供的参数与签名不匹配
我有一个包含rect元素和text元素的SVG index.htmlJavascript d3Service/d3-ng2-service TypeScript TS2346提供的参数与签名不匹配,javascript,typescript,d3.js,svg,Javascript,Typescript,D3.js,Svg,我有一个包含rect元素和text元素的SVG index.html <svg id="timeline" width="300" height="100"> <g transform="translate(10,10)" class="container" width="280" height="96"> <rect x="10" y="30" width="48" cy="10" r="30" height="60" class="tim
<svg id="timeline" width="300" height="100">
<g transform="translate(10,10)" class="container" width="280" height="96">
<rect x="10" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day1"></rect>
<rect x="58" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day2"></rect>
<rect x="106" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day3"></rect>
<rect x="154" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day4"></rect>
<text class="textnumbers" id="day1" x="22.8" y="50">1</text>
<text class="textnumbers" id="day2" x="70.8" y="50">1</text>
<text class="textnumbers" id="day3" x="118.8" y="50">1</text>
<text class="textnumbers" id="day4" x="116.8" y="50">1</text>
</g>
</svg>
我在选择时遇到TS2346错误:
错误TS2346:提供的参数与呼叫目标的任何签名都不匹配。
D3服务的索引d.ts
为:
第162行写道:
select(选择器:字符串):选择代码>
我假设我从index.d.ts
中得到了错误的元素类型,我应该使用除SVGRectElement
和TextElement
之外的其他元素,但我不知道是什么。Angular2组件在实践中运行良好。如何读取index.d.ts
文件以找到正确的元素类型?谢谢 正如您在select()
方法签名中所看到的:
select(选择器:字符串):选择代码>
select方法返回一个Selection
元素,因此无法转换为SVRectElement
。此外,强制转换(如果需要)应该位于调用的方法前面,如下所示:let ele=D3.select(rect_id).node()代码>
但在这种情况下,不需要强制转换,因此代码应为:
让rectEle=self.d3.select(rectId);
let day = 1;
let rect_id = "rect#day" + day;
let ele = D3.select<SVGRectElement>(rect_id).node();
let label_id = rect_id.replace("rect", ".textnumbers");
let numberEle = D3.select<TextElement>(label_id);