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

backgroundColor doesn't work since v4? #11002

Closed
DavideViolante opened this issue Dec 19, 2022 · 6 comments · Fixed by #11003
Closed

backgroundColor doesn't work since v4? #11002

DavideViolante opened this issue Dec 19, 2022 · 6 comments · Fixed by #11003

Comments

@DavideViolante
Copy link

DavideViolante commented Dec 19, 2022

Expected behavior

On latest v3 I used options.backgroundColor: [array of strings of hex colors]. On v4 it doesn't seem to have any effect, and I can't find any migration about that.

Edit: it seems it must be inside datasets array, where is this mentioned in the migration from v3 to v4?!

Current behavior

Default light blue colors are shown.

Reproducible sample

https://codepen.io/davideviolante/pen/NWBWdaa

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.1.1

Browser name and version

No response

Link to your project

No response

@stockiNail
Copy link
Contributor

See #10927

You could disable the colors plugin or move the backgroundColor in the dataset definition.

@LeeLenaleee
Copy link
Collaborator

I think this is an oversight in the check if the plugin needs to be enabled.

@DavideViolante
Copy link
Author

Thanks I moved inside datasets[i].backgroundColor and it seems to work like before.
But this should be mentioned in the migration docs or somewhere.

@stockiNail
Copy link
Contributor

@DavideViolante as @LeeLenaleee outlined, what I proposed is a workaround. It seems to be an oversight in the plugin implementation.

@LeeLenaleee I think the issue is

function containsColorsDefinitions(
descriptors: ColorsDescriptor[] | Record<string, ColorsDescriptor>
) {

because is invoked passing the options but I doesn't seem matching the type. I think it should ColorsDescriptor (no array) but maybe I'm wrong.

@LeeLenaleee
Copy link
Collaborator

The problem is that the function is invoked with the dataset and the elements but not the root of the options in which you can also define it.

const {
options: {elements},
data: {datasets}
} = chart.config;
if (!options.forceOverride && (containsColorsDefinitions(datasets) || elements && containsColorsDefinitions(elements))) {

@stockiNail
Copy link
Contributor

@LeeLenaleee FYI I have submitted a PR.

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

Successfully merging a pull request may close this issue.

3 participants