问题
I'm trying to implement a tooltip in svg using Angular, d3 v4, d3-tip.
here's the JS logic
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);
}
The problem is that nothing is shown on screen but I have noticed that when I hover the elements the tip function is triggered ( chrome debugger )
return (
`<strong>Frequency:</strong> <span style="color:red"> test</span>"`
)
Here's a demo for code working but unfortunately I can't reproduce the error.
I want to mention that is my real example that this code bellow is inside an observable subscription
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);
}
回答1:
If your issue is tooltip not showing as per dynamic data then replace the below code, the tooltip will start showing -
tip.offset([-10, 0]).html(d => {
return (
"<strong>Frequency:</strong> <span style='color:red'>" +
d.train + "</span>"
);
});
Hope it will help you :)
来源:https://stackoverflow.com/questions/58284042/tooltip-using-d3-tip-not-showing