Chartjs-How to download chart js image as bmp

0👍

You can solve your problem without BMP. The black background happens because the image background is transparent and the default photo viewer on Windows renders transparency as black.

Set your chart background color explicitly, like this:

Chart.plugins.register({
  beforeDraw: function(chartInstance) {
    var ctx = chartInstance.chart.ctx;
    ctx.fillStyle = '#fff';  // or whatever background color you want
    ctx.fillRect(0, 0, chartInstance.chart.width, chartInstance.chart.height);
  }
});

If you actually want to generate a BMP (which isn’t necessary in this case), you’ll have to convert the generated PNG to BMP. For this you can use a library like JIMP.

Leave a comment