chartjs / chartjs/chartjs-plugin-datalabels

Error: Cannot set properties of undefined (setting '_listened')

Open
#309 12 comments 3 reactions 0 assignees View on GitHub
needs test case
Dominant language
JavaScript
Stars
920
Forks
507
PR merge metrics
No merged PRs in 30d

Description

### Definition
I have an application created with next.js which I am making client-side routing. I am using chartjs with datalabels on one page and I am getting a `Cannot set properties of undefined (setting '_listened')` error while making the page transition. It is not always happening. I couldn't find the exact case and I can not reproduce it with certain steps. But When I tried to make lots of concurrent page transition click sometimes it happens. So it is an unpredictable error that I am facing while demoing the application.

Can You please look into the details and provide some solution? Thanks

### Implementation Details:
I have one dashboard page which has one doughnut chart. Also, I have different charts on some detailed reports. On the dashboard, I don't want to see the data labels but on reports, I want to have them.
The plugin is

I am registering Datalabel Plugin globally like below:
```
import { ArcElement, Chart, Legend } from 'chart.js';
import ChartDataLabels from 'chartjs-plugin-datalabels';

Chart.register(ArcElement, Legend, ChartDataLabels);
```
I am disabling the datalabels plugin when it is not desired according to user selection with the below option settings. And Datalabels is disabled on the page, I am getting this error.

![image](https://user-images.githubusercontent.com/41747037/160429771-bce1828d-2c16-4ee3-8e73-a74090eacabe.png)

### extra detail
Whole stack trace of error message on console
![image](https://user-images.githubusercontent.com/41747037/160429159-6ccf594e-ae66-4fc0-8651-9c147d6d29bd.png)

I have followed up error line it it is showing the line in redbox

![image](https://user-images.githubusercontent.com/41747037/160431636-3ef9dcf9-08ad-4baf-b601-ee558c8001bc.png)

### versions
"chart.js": "^3.6.1",
"chartjs-plugin-datalabels": "^2.0.0",

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.