Error: Cannot set properties of undefined (setting '_listened')
See original GitHub issueDefinition
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.
extra detail
Whole stack trace of error message on console
I have followed up error line it it is showing the line in redbox
versions
"chart.js": "^3.6.1",
"chartjs-plugin-datalabels": "^2.0.0",
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (4 by maintainers)
I got the same error. In my case I registered the plugin globally but needed only in one chart. I switch from registered globally to the exact chart and now I don’t have the error anymore.
The conf of the chart that is using this plugin is something like this (I’m using plain JS) :
{ type: 'pie', data: {.....}, plugins: [ChartDataLabels], options: {...} }
That is the idea. I’m not aware of any plugin doing that in a minor version thought, so I don’t have any proof.