![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
chartjs-plugin-autocolors
Advanced tools
Automatic color generation for Chart.js
The generation is based on Janus Troelsen's answer at Stack Overflow.
This plugin requires Chart.js 3.0.0 or later. Could work with v2, but it is not supported.
NOTE the plugin does not automatically register.
NPM:
npm i --save chartjs-plugin-autocolors
CDN:
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-autocolors"></script>
ESM
import autocolors from 'chartjs-plugin-autocolors';
CDN
const autocolors = window['chartjs-plugin-autocolors'];
All charts
Chart.register(autocolors);
Single chart
const chart = new Chart(ctx, {
// ...
plugins: [
autocolors
]
});
If registered globally, it might be desirable to disable the autocolors for some charts
const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
enabled: false
}
}
}
});
NOTE: 'dataset'
mode does not work properly for Pie / Doughnut charts, so using 'data'
mode with those charts is advised.
There are two modes, 'dataset'
(default) 'data'
and 'label'
'dataset'
mode, a new color is picked for each dataset.'data'
mode, an array of colors, equivalent to the length of data is provided for each dataset.'label'
mode, color is picked for each different dataset label.const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
mode: 'data'
}
}
}
});
A customize
function can be provided to customize the generated colors.
The function is expected to return object containing background
and border
properties,
with values acceptable as colors by Chart.js.
const lighten = (color, value) => Chart.helpers.color(color).lighten(value).rgbString();
const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
customize(context) {
const colors = context.colors;
return {
background: lighten(colors.background, 0.5),
border: lighten(colors.border, 0.5)
};
}
}
}
}
});
offset
option can be used to offset the color generation by a number of colors.
const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
offset: 5
}
}
}
});
Sometimes you might need to color multiple adjacent datasets with same color. The repeat
option is for that use case.
const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
repeat: 2
}
}
}
});
This plugin uses a generator function, so it is not compatible with Internet Explorer.
chartjs-plugin-autocolors.js
is available under the MIT license.
FAQs
Automatic color generation for Chart.js
The npm package chartjs-plugin-autocolors receives a total of 4,602 weekly downloads. As such, chartjs-plugin-autocolors popularity was classified as popular.
We found that chartjs-plugin-autocolors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.