Skip to content

Integration

import { Chart } from 'chart.js'
import autocolors from 'chartjs-plugin-autocolors'
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-autocolors"></script>

When loaded from a CDN, the plugin is exposed as a global instead of a module export.

const autocolors = window['chartjs-plugin-autocolors']

Register the plugin for every chart on the page:

Chart.register(autocolors)

Or register it for a single chart only:

const chart = new Chart(ctx, {
// ...
plugins: [autocolors],
})

If registered globally, it might be desirable to disable autocolors for some charts:

const chart = new Chart(ctx, {
// ...
options: {
plugins: {
autocolors: {
enabled: false,
},
},
},
})

The plugin uses a generator function, so it is not compatible with Internet Explorer.