chartjs / chartjs/Chart.js

Cannot read properties of undefined (reading 'labels')

Open
#11,380 2 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

When calling generateLabels and passing the current Chart object as a parameter I would expect the generateLabels function to run.

### Current behavior

When running generateLabels with the Chart object passed as a parameter it fails with TypeError: Cannot read properties of undefined (reading 'labels').
![image](https://github.com/chartjs/Chart.js/assets/6824137/fde02e09-7645-4c52-8ed3-f6d1fc1eaede)

When debugging the Doughnut controller overrides generateLabels function I can see we try to get the data from "chart.data" but this property doesn't exist. Hoever, the chart.chart.data exist.

![image](https://github.com/chartjs/Chart.js/assets/6824137/e5b822c2-4a97-430d-9ec8-8cc81b4d9116)

### Reproducible sample

https://codesandbox.io/s/chartjs-error-legend-labels-dhmrtd

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

I'm not able to show the legend label on my chart.

### chart.js version

4.3.0

### Browser name and version

_No response_

### Link to your project

_No response_

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.