ChartJs Custom Tooltip is stucked on UI
See original GitHub issueHi, I have included chart.js custom tooltip using example in official docs.
Problem:
If someone have mouse on chart then this custom tooltip is displayed. And while the mouse is in chart, if someone uses tabs/enter to navigate to another page, this custom tooltip function is not called. As a consequence, tooltip is not removed from UI in rest of the interactions with app. I have inspected the core library and I think it was only detecting mouseout
event which in this case, didn’t call this custom tooltip hook.
Below attached is my code for tooltip configuration, and I am using react-chartjs-2 wrapper to consume chart.js Chart.js version: 2.9.1 react-chartjs-2: 2.8.0
tooltips: {
enabled: false,
placement: 'left',
caretSize: 5,
cornerRadius: 6,
custom: function(tooltipModel) {
let tooltipEl = document.getElementById('custom-tooltip');
// Create element on first render
if (!tooltipEl) {
tooltipEl = document.createElement('div');
tooltipEl.id = 'custom-tooltip';
document.body.appendChild(tooltipEl);
}
// Hide if no tooltip
if (tooltipModel.opacity === 0) {
tooltipEl.style.opacity = 0;
return;
}
let position = this._chart.canvas.getBoundingClientRect();
let clickPointPosition = position.left + window.pageXOffset + tooltipModel.caretX;
// Display, position, and set styles for font
tooltipEl.style.opacity = 0.9;
tooltipEl.style.position = 'absolute';
tooltipEl.style.left = (clickPointPosition < tooltipEl.offsetWidth ? clickPointPosition : clickPointPosition - tooltipEl.offsetWidth) + 'px';
tooltipEl.style.top = position.top + window.pageYOffset + tooltipModel.caretY + 'px';
tooltipEl.style.fontFamily = tooltipModel._bodyFontFamily;
tooltipEl.style.fontSize = tooltipModel.bodyFontSize + 'px';
tooltipEl.style.fontStyle = tooltipModel._bodyFontStyle;
tooltipEl.style.padding = tooltipModel.yPadding + 'px ' + tooltipModel.xPadding + 'px';
tooltipEl.style.pointerEvents = 'none';
}
},
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
ChartJS: Custom tooltip always displaying - Stack Overflow
Im trying to create a custom tooltip. According to the documentation, this should be easy: var myPieChart = new Chart(ctx, { type: 'pie',...
Read more >Tooltip - Chart.js
External tooltips allow you to hook into the tooltip rendering process so that you can render the tooltip in your own custom way....
Read more >Tooltip for bar chart is getting hide while hovering & show axis ...
Since chart width is too small, tooltip div is cropped due to overflow: hidden property of their parent element. We suggest you to...
Read more >Tooltip | Common Settings - AnyChart Documentation
Tooltip is a text box that is hidden by default and can be displayed when a point on a chart is hovered over....
Read more >How to use Chart.js for Dataset Visualization? - DevTeam.Space
The best option is to use a custom solution that lets you graph and animate your content in a unique and professional way....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Reproduces with master: https://jsfiddle.net/p4cjbeg7/ (in chrome, not in firefox)
Note: had to add
animation: false
andvar tooltipModel = this
to make it work with v3.I tried this in Firefox and the tooltip was hidden when i triggered the chart hiding via the keyboard.