0

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)"
    }
}

1 Answers1

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

LeeLenalee
  • 27,463
  • 6
  • 45
  • 69