-
Notifications
You must be signed in to change notification settings - Fork 484
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
Fixed: Cannot read property '$context' of null #54
Conversation
Since there is a possibility to get `label` as `null` (https://github.com/chartjs/chartjs-plugin-datalabels/blob/master/src/plugin.js#L178) it should be also filtered out from updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'm not sure when that happen though, can you build a jsfiddle that reproduces this issue?
src/plugin.js
Outdated
@@ -232,8 +232,10 @@ Chart.plugins.register({ | |||
update = updates[i]; | |||
if (update[1]) { | |||
label = update[0][EXPANDO_KEY]; | |||
label.$context.active = (update[1] === 1); | |||
label.update(label.$context); | |||
if (label && label.$context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would only test for label
since label.$context
should always be defined, else that's a bug and should not be silently ignored.
Reproduced in a complex chart but unfortunately can not isolate the issue :( |
Can you share your complex chart code? I'm curious why that happens because label could be null only if the element is hidden or skipped, in which case it should not be part of any interactions ( |
I'd share it already if I could. |
Thanks @pfrankov |
Since there is a possibility to get
label
asnull
(https://github.com/chartjs/chartjs-plugin-datalabels/blob/master/src/plugin.js#L178) it should be also filtered out from updating.