我正在尝试使用Angular,d3 v4,d3-tip在svg中实现工具提示。
这是JS逻辑
var data = [{
train: 1
}, {
train: 2
}, {
train: 3
}, {
train: 4
}]
const tip = d3Tip()
let svg =d3.select('svg')
tip
.offset([-10, 0])
.html(d => {
return (
`<strong>Frequency:</strong> <span style="color:red"> test</span>"`
)
})
svg.call(tip)
let selectedElms = d3.selectAll('circle')
.data(data, function(d) {
console.log(this.id)
return (d && d.train) || this['id'];
})
selectedElms
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
}
问题是屏幕上什么都没有显示,但是我注意到当我将元素悬停在tip
函数上(chrome调试器)
return (
`<strong>Frequency:</strong> <span style="color:red"> test</span>"`
)
这里是demo,用于代码工作,但是很遗憾,我无法重现该错误。
我要提到的是我的真实示例,该代码位于可观察的订阅中
let selectedElms = d3.selectAll('circle')
.data(data, function(d) {
console.log(this.id)
return (d && d.train) || this['id'];
})
selectedElms
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
}