0

using react chartjs i m trying to download chart as a image. this is my code:

 const saveAsImage = () => {
    const imageLink = document.createElement('a');
    
    imageLink.download ='img.png';
    imageLink.href =chartRef.current.toBase64Image('image/jpg', 1);
    
    imageLink.click();
  }

downloaded image background colour should be clear

3r1c
  • 376
  • 5
  • 20
Vani Y
  • 1
  • https://stackoverflow.com/questions/43664722/how-to-save-chart-js-charts-as-image-without-black-background-using-blobs-and-fi/53946660#53946660 Have you checked this – RRR Jan 04 '23 at 08:17

1 Answers1

0

You're using toBase64Image('image/jpg', 1) and jpg images don't have transparent backgrounds. Try with image/png.

xaleel
  • 173
  • 5