Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

85
Views
Hide tooltip when hovering over null-values in chart.js

I am currently using a line-chart with chart.js 3.5.0 and react-chart-js 3.0.4, given two datasets.

The first dataset has data in {x,y}-format with null-values for some y. When hovering over those null-values, the tooltip jumps to the start of the second dataset. In this case, I would like to hide the tooltip, but approaching the problem with callbacks didn't work.

Has anybody experienced the same issue?

Screenshot

codesandbox

const options = {
    interaction: {
        intersect: false
    },
    maintainAspectRatio: true,
    animation: false,
    plugins: {
        tooltip: {
            mode: 'nearest',
            axis: 'x',
            position: 'average',
            yAlign: "bottom"
        },
    },
    scales: {
        y: {
            type: 'linear',
            beginAtZero: true,
            min: 0,
            grace: '20%',
        }
    },
    chartArea: {
        backgroundColor: "rgb(240,240,240)"
    }
}
8 months ago · Santiago Gelvez
1 answers
Answer question

0

You can use mode: 'x' in your tooltip config. Together with setting pointHitRadius to 0 in both datasets makes it so you dont have duplicate values in your tooltip.

Example: https://codesandbox.io/s/hardcore-brown-1vxcjh?file=/src/components/CChart.jsx

8 months ago · Santiago Gelvez Report
Answer question
Find remote jobs