-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read properties of null (reading 'getLabelAndValue') in function createTooltipItem() of plugin.tooltip.js #11315
Comments
May be related to #11206. The stack trace is pretty similar, and it also happens randomly when the user is interacting with the chart during data updates. |
|
Possible solution: function createTooltipItem(chart, item) {
const { element, datasetIndex, index } = item;
const controller = chart.getDatasetMeta(datasetIndex).controller;
if (controller) {
const { label, value } = controller.getLabelAndValue(index);
return {
chart,
label,
parsed: controller.getParsed(index),
raw: chart.data.datasets[datasetIndex].data[index],
formattedValue: value,
dataset: controller.getDataset(),
dataIndex: index,
datasetIndex,
element
};
}
else {
return {
chart,
label: '',
formattedValue: '',
dataIndex: index,
datasetIndex,
element
};
}
} |
any update? i got same issue |
I encountered chartjs#11315 under the following circumstances: 1. Position the cursor over the chart area, such that it causes a tooltip to be shown. 2. Move the cursor out of the chart area, such that the tooltip remains visible. 3. Cause the chart contents to be changed, such that the dataset referenced by the active tooltip element is no longer valid. 4. Move the mouse again. This triggers an `inChartArea = false` event, so it reuses the previous, now invalid, active elements. This fixes chartjs#11315 under the circumstances for which I've reproduced it, but there may be others.
@schavelev, you said that you're able to trigger this "when the mouse pointer is in the canvas area, but the canvas container is in the process of being destroyed" - can you give any details, or a reproducible codepen.io / codesandbox.io sample? I'm able to reproduce this error in the following circumstances, but this sounds different than what you're seeing.
|
…11596) * Fix for getLabelAndValue on null controller I encountered #11315 under the following circumstances: 1. Position the cursor over the chart area, such that it causes a tooltip to be shown. 2. Move the cursor out of the chart area, such that the tooltip remains visible. 3. Cause the chart contents to be changed, such that the dataset referenced by the active tooltip element is no longer valid. 4. Move the mouse again. This triggers an `inChartArea = false` event, so it reuses the previous, now invalid, active elements. This fixes #11315 under the circumstances for which I've reproduced it, but there may be others. * Further fixes for elements added / changed This possibly fixes #11365.
Expected behavior
No error message
Current behavior
Sometimes the following error occurs:
plugin.tooltip.js:123 Uncaught TypeError: Cannot read properties of null (reading 'getLabelAndValue')
at createTooltipItem (plugin.tooltip.js:123:37)
at Tooltip._createItems (plugin.tooltip.js:603:25)
at Tooltip.update (plugin.tooltip.js:645:27)
at Tooltip.handleEvent (plugin.tooltip.js:1160:14)
at Object.afterEvent (plugin.tooltip.js:1257:25)
at callback (helpers.core.ts:109:15)
at PluginService._notify (core.plugins.js:60:11)
at PluginService.notify (core.plugins.js:42:25)
at Chart.notifyPlugins (core.controller.js:1148:26)
at Chart._eventHandler (core.controller.js:1197:10)
createTooltipItem @ plugin.tooltip.js:123
_createItems @ plugin.tooltip.js:603
update @ plugin.tooltip.js:645
handleEvent @ plugin.tooltip.js:1160
afterEvent @ plugin.tooltip.js:1257
callback @ helpers.core.ts:109
_notify @ core.plugins.js:60
notify @ core.plugins.js:42
notifyPlugins @ core.controller.js:1148
_eventHandler @ core.controller.js:1197
listener @ core.controller.js:1006
(anonymous) @ platform.dom.js:243
(anonymous) @ helpers.extras.ts:40
requestAnimationFrame (async)
(anonymous) @ helpers.extras.ts:38
This error occurs when the mouse pointer is in the canvas area, but the canvas container is in the process of being destroyed.
Reproducible sample
Chart.js/src/plugins/plugin.tooltip.js
Line 123 in abbd5a7
Optional extra steps/info to reproduce
No response
Possible solution
No response
Context
No response
chart.js version
v4.3.0
Browser name and version
Google Chrome 113.0.5672.127
Link to your project
No response
The text was updated successfully, but these errors were encountered: