Skip to content

backgroundColor doesn't always support string array #11912

@teodorachiosa

Description

@teodorachiosa

Expected behavior

backgroundColor should support string and string[] in:
Chart.defaults.backgroundColor

Current behavior

Using TypeScript, I'm getting this error when using an array of colors for backgroundColor:

Chart.defaults.backgroundColor = ['red', 'blue'];
TS2322: Type 'string[]' is not assignable to type 'Scriptable<Color, ScriptableContext>'.

All Chart.js examples use arrays of colors, this should be supported.

A similar thing has been logged here as an improvement: #10123, but I think it's a bug.

Reproducible sample

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUG2pjFQCYCmedAFcANjDpUARujIBrAOaEhAOx7III6HAC8cANokAxHjwAGc6ZIAaUofMnzJALot2rAG6Y4ZGAA8dcDwQZEIgfMrc8nwwAKIifGERAEIAngCSPAAUAEQgKZyw2QCUcOh0cAASACoAsgAyyOjKnnRxCeEwrp5QcHkF8LrKfADuKJQwmT6+NghscPNwMClgfABcpGDAfNZzCzzoMOjrs6wLZ3Ai6JJ8InTretkASnw82TbZSSJCfG9w2QCaN00w1+2QA4lA+OFQQAFIRQMDxUEAeSgTSi2ScVl250CBzK0Tu+hOuNxl2uInWRjgEDwcAAahAYHwGNjTqSzvtDvcAIwAJhsPIAnDYAMw2ACsNgFcFFWJx52wTgV2DZZwgYBgwAgyiJJPOdDI6HieoVZ18xzN5yt81VNrgKUt7I59uwVrdzpwbGwRVcbCAA

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

4.4.4

Browser name and version

Chrome: 129.0.6668.70 (Official Build) (64-bit)

Link to your project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: typesTypescript type changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions