chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.94k stars 11.89k forks source link

Allow default color palette to be modified in Colors plugin #11686

Closed TedCha closed 3 months ago

TedCha commented 4 months ago

Feature Proposal

I believe it would be a useful feature to allow the default color palette of the chart.js Colors plugin to be adjustable by a user before registration. This would allow for a custom color palette to be initialized once rather than in every chart that is defined.

Possible Implementation

Looking at the implementation, I think this would be achievable by defining a palette parameter within the defaults and options and then using that property instead of the BORDER_COLORS constant to store the default colors. The options parameter of the beforeLayout function would need to be passed down to where the color retrieval takes place (e.g. getBorderColor and getBackgroundColor).

LeeLenaleee commented 4 months ago

I thought the idea was to not support this kind of customization. If you want this you can use an existing or custom plugin or just pass your own colors

TedCha commented 4 months ago

@LeeLenaleee Thanks for the reply. I didn't realize that the fixed color palette was intentional. You're right that it's easy to create a custom plugin that's similar to the existing Colors plugin but I thought it would be an relatively easy thing to build in and give the user more color palette flexibility while still being able to rely on the defaults.

Though completely understand if the fixed color palette is by design for default standardization. I'll close the ticket if so.

LeeLenaleee commented 3 months ago

Closing this issue as this is not something we are going to support.

There are 2 external plugins that can be used depending on your version of chart.js: