Skip to content

Commit b5f93d1

Browse files
committed
set background color white
1 parent d0a52f0 commit b5f93d1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

desktop/frontend/src/lib/chart.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ChartConfiguration } from "chart.js";
1+
import { type ChartConfiguration, type Plugin } from "chart.js";
22

33
type Vertex = {
44
x: number;
@@ -42,9 +42,21 @@ export function setupPlot(values: number[]): ChartConfiguration {
4242
],
4343
};
4444

45+
const plugin: Plugin = {
46+
id: 'customCanvasBackgroundColor',
47+
beforeDraw: (chart, args, options) => {
48+
const {ctx} = chart;
49+
ctx.save();
50+
ctx.globalCompositeOperation = 'destination-over';
51+
ctx.fillStyle = options.color || '#FFFFFF';
52+
ctx.fillRect(0, 0, chart.width, chart.height);
53+
ctx.restore();
54+
}
55+
};
4556
const config: ChartConfiguration = {
4657
type: "scatter",
4758
data: data,
59+
plugins: [plugin],
4860
options: {
4961
scales: {
5062
x: {

0 commit comments

Comments
 (0)