chartjs / chartjs/Chart.js

Chart.defaults.datasets is empty/cannot set properties of undefined

Open
#11,176 0 comments 4 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

This code used to work in 3.9.1:

```
import { Chart } from "chart.js";

Chart.defaults.datasets.doughnut.backgroundColor = backgroundColors;
```

### Current behavior

Now I receive an error:

```
TypeError: Cannot set properties of undefined (setting 'backgroundColor')
```

Additionally, `Chart.defaults.datasets` is now an empty object, `{}`.

I can't reproduce it using the codepen, so I think something is wrong with my import statement/the auto package. The type of Chart.defaults.datasets is now {} when using `chart.js/auto`, so something changed but I'm not sure what/don't see this called out in the migration guide.

### Reproducible sample

https://codepen.io/leelenaleee/pen/WNyJXEe

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

_No response_

### chart.js version

4.1.2

### 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.