Skip to content
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

Critical: Cannot read properties of undefined (reading '_labels') <> Angular 12 #354

Open
vatsal2210 opened this issue Dec 2, 2022 · 3 comments

Comments

@vatsal2210
Copy link

Here are my chart.js versions:

Error: Cannot read properties of undefined (reading '_labels')

Problem statement:

I can't produce the workflow or step-by-step why it creates an issue. I make sure labels are assigned before I load a chart.

Still doesn't understand the exact cause of the issue.

Versions:

 "chart.js": "3.7.0",
  "chartjs-plugin-datalabels": "2.0.0",

The full error:

core.js:7744 ERROR TypeError: Cannot read properties of undefined (reading '_labels')
    at Object.afterDatasetsDraw (chartjs-plugin-datalabels.esm.js:1304:43)
    at callback (helpers.segment.js:92:15)
    at PluginService._notify (chart.esm.js:4922:19)
    at PluginService.notify (chart.esm.js:4909:25)
    at Chart.notifyPlugins (chart.esm.js:6047:26)
    at Chart._drawDatasets (chart.esm.js:5797:10)
    at Chart.draw (chart.esm.js:5768:10)
    at chart.esm.js:64:15
    at Map.forEach (<anonymous>)
    at Animator._update (chart.esm.js:42:18)

Is there anything else I should provide to find the issue? I appreciate any help, as it is impacting our production environment charts.

@simonbrunel
Copy link
Member

We really need a way to reproduce this issue such as a CodePen or a repository.

@serhii-kucherenko
Copy link

I had the same issue. Seems if you have 2 and come charts on the same page and not all of them using datalabels it still tries to read those labels

@encongithubuser
Copy link

In my case the solution was to initially set some default data in the line configuration before I populate it. Because I get data from the API, it comes in later, and sometimes I got this error. Now if I initialize the ChartConfiguration like this, the error is gone:

lineChartData: ChartConfiguration['data'] =
{datasets : [{ data: [0], label: 'S1', backgroundColor: '#1DAA68', borderColor: '#4BA87D', type: 'bar' },
{ data: [0], label: 'S2', backgroundColor: 'rgba(0,112,192,0.2)', borderColor: '#4BA87D', type: 'bar' },
{ data: [0], label: 'S3', backgroundColor: 'rgba(0,176,80,0.2)', borderColor: '#4BA87D', type: 'bar' }
], labels : ['']};

When the chart is loaded, you will see that there is a short moment its set to the initial state and later filled. I aleady tried to hide the chart before the data was loaded, but it didn't helped in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants