chartjs / chartjs-plugin-annotation

Annotation plugin for Chart.js
MIT License
603 stars 325 forks source link

"Cannot destructure property 'visibleElements' of 'chartStates.get(...)' as it is undefined" when trying to register plugin #746

Closed nikoisonfire closed 2 years ago

nikoisonfire commented 2 years ago

I'm getting this error after trying to register the plugin

image

Error pops up without even using the annotations in any Chart.

image

Using the auto-import feature for chart.js, but have also tried Chart.register({...registerables, annotationsPlugin}) spread and which also gives the same error

stockiNail commented 2 years ago

@nikoisonfire may I ask which versions you are using (plugin and chartjs)? And can you reproduce the error in codesandox or wherever in order to debug it?

stockiNail commented 2 years ago

@nikoisonfire I have prepared a simple codesandobx but I wasn't able to reproduce the issue.

https://codesandbox.io/s/frosty-bush-6wq68k?file=/src/index.js

nikoisonfire commented 2 years ago

That's strange. I've forked your sandbox to replicate the behaviour using auto import et al. https://codesandbox.io/s/sad-shape-jzw7so?file=/src/index.js , but it seems to work there.

I'll come back here if I can't fix it.

nikoisonfire commented 2 years ago

First of all, thank you for your response!! Didn't want to leave this unsaid.

So it looks like there is a collision with the chartjs-chart-geo plugin I'm using on a different module, I've changed the import order so the annotation comes before chart geo and it seems to work for now.

Really odd behaviour tbh, but this might happen if you use "vanilla" HTML instead of a framework, something will always go tuts up. shrug

For reference the versions I'm using "chart.js": "^3.7.1", "chartjs-chart-geo": "^3.7.2", "chartjs-plugin-annotation": "^1.4.0"

FYI: I've tried downgrading C.js to 3.7.0 and 3.6.9, and plugin-annotation to 1.3.1 , no difference.

stockiNail commented 2 years ago

@nikoisonfire thank you for your details. I'd like to understand better why there is this collision (it shouldn't). ASA I'll have more details I'll update this issue.