Open vatsal2210 opened 1 year ago
We really need a way to reproduce this issue such as a CodePen or a repository.
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
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.
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:
The full error:
Is there anything else I should provide to find the issue? I appreciate any help, as it is impacting our production environment charts.