[Chartjs]-Why is the background black when with Chartjs export to a image

1👍

This is a bit more complicated than simply what image format is being used.
You need to explicitly set the canvas background to white. But exactly when to do this can be tricky. Please see my answer in a similar question.

0👍

I tried to send chart as image from Angular 2+ (canvas element) to spring boot for render image to PDF. I encountered blacked background problem. After collecting information about this problem. I decided to unite solution in the one comment to find solution easily at next time.

 <canvas #canvas"> </canvas>

 @ViewChild('canvas', { static: false }) canvas: ElementRef<HTMLCanvasElement>;

I rendered chart to canvas and get canvas element at .ts file as PNG format and send PNG to backend.

const base64Canvas = this.canvas.nativeElement.toDataURL("image/png").split(';base64,')[1];

Leave a comment