File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1- import { type ChartConfiguration } from "chart.js" ;
1+ import { type ChartConfiguration , type Plugin } from "chart.js" ;
22
33type 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 : {
You can’t perform that action at this time.
0 commit comments