![](/img/trans.png)
[英]Angular 4 - argument of type string[] is not assignable to type parameter of type 'string'
[英]Angular Typscript Argument of type 'string' is not assignable to parameter of type 'Element'
d3js 的 angular 中的 Typescript 出現 3 個元素錯誤。 我正在為其創建鼠標懸停以顯示與條形圖數據相對應的標簽和值數據。 我試過聲明字符串。 我什至在 tsconfig.js 文件中添加了一個 ("noImplicitAny": false)。 我試圖找出問題出在哪里。 我的問題的代碼在這里:
// object.enteries: creates arrays of an element
svg.selectAll("bars")
.data(sortedata)
.enter()
.append("rect")
.attr('x', function(d):any {return xAxis(d[0])})
.attr('y', function(d){return yAxis(Number(d[1]))} )
.attr('width', xAxis.bandwidth())
.attr("height", (d) => this.height - yAxis(Number(d[1])))
.attr("fill", "#d04a35")
.on('mouseover', mouseover)
const tip = d3.select(".tooltip")
function mouseover(event,d){
tip
style('left', `${event.clientX + 15}px`)
style('top' , `${event.clientX + 15}px`)
style('opacity', 0.88)
tip.select("h3").html("tag:" +d[0]),
tip.select("h4").html("value:" +d[1]);
}
我相信你需要一個.
在 style 關鍵字之前。
tip
.style('left', `${event.clientX + 15}px`)
.style('top' , `${event.clientX + 15}px`)
.style('opacity', 0.88)
但是,如果您想一次設置多個樣式,d3 文檔給出了示例
如果要一次設置多個樣式屬性,請使用 object 文字。 例如:
selection.style({stroke: "black", "stroke-width": "2px"});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.