chartjs / chartjs/Chart.js

Tooltip title callback is run with empty parameter array for filtered tooltips

Open
#12,274 0 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

When a tooltip has been filtered out, its callbacks should not run on hover. Running callbacks with missing parameters might have surprising consequences the user does not want.

### Current behavior

At least the title callback is run with an empty TooltipItem array as parameter. Depending on how your callback is structured, this could break your code

### Reproducible sample

https://codepen.io/ajuvonen/pen/OPWvmwG

### Optional extra steps/info to reproduce

For demo purposes, all tooltips have been disabled. The title callback is run for each data point, however, and this causes console errors.

### Possible solution

_No response_

### Context

I have had to write a special guard in my title callbacks, even though in normal situations they can rely that the TooltipItem array is never empty.

### chart.js version

4.5.1

### Browser name and version

Firefox 152

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reproducible CodePen sample and trace the tooltip filtering and title-callback behavior in Chart.js 4.5.1. Confirm which path invokes the callback with an empty TooltipItem array, then verify that filtered-out tooltips no longer invoke hover callbacks and that the existing tooltip tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.