0👍
Here is the codepen with a working sample. https://codepen.io/stockinail/pen/OJENbwM
An additional plugin is needed to color the background of the canvas, as reported in CHARt.JS doc https://www.chartjs.org/docs/latest/configuration/canvas-background.html:
const plugin = {
id: 'custom_canvas_background_color',
beforeDraw: (chart) => {
const {ctx} = chart;
ctx.save();
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, chart.width, chart.height);
ctx.restore();
}
};
The plugin must be added to chart configuration, as following:
const myChart = new Chart(ctx, {
type: 'bar',
plugins: [plugin], // <<--- adds plugin to color the background of the canvas
data: chartData
});
Source:stackexchange.com