How to save Chart JS charts as image without black background using blobs and filesaver?

If you want a customized background color then, you’d have to draw a background with your preferred color, and you can do so, like this … var backgroundColor=”white”; Chart.plugins.register({ beforeDraw: function(c) { var ctx = c.chart.ctx; ctx.fillStyle = backgroundColor; ctx.fillRect(0, 0, c.chart.width, c.chart.height); } }); DEMO // draw background var backgroundColor=”white”; Chart.plugins.register({ beforeDraw: function(c) { … Read more

HTML5 File API downloading file from server and saving it in sandbox

I’m going to show you how to download files with the XMLHttpRequest Level 2 and save them with the FileSystem API or with the FileSaver interface. ##Downloading Files## To download a file you will use the XMLHttpRequest Level 2 (aka XHR2), which supports cross-origin requests, uploading progress events, and uploading/downloading of binary data. In the … Read more

Download binary file with Axios

I was able to create a workable gist (without using FileSaver) as below: axios.get(“http://my-server:8080/reports/my-sample-report/”, { responseType: ‘arraybuffer’, headers: { ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/pdf’ } }) .then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement(‘a’); link.href = url; link.setAttribute(‘download’, ‘file.pdf’); //or any other extension document.body.appendChild(link); link.click(); }) .catch((error) => console.log(error));