Skip to content

Instantly share code, notes, and snippets.

@pedroviniv
Created June 5, 2020 03:36
Show Gist options
  • Save pedroviniv/2f1c8dcf7cc5310c17a11234f9d6bfd5 to your computer and use it in GitHub Desktop.
Save pedroviniv/2f1c8dcf7cc5310c17a11234f9d6bfd5 to your computer and use it in GitHub Desktop.
apache echarts get canvas image in base64
const img = new Image();
// get the chart instance data as url
img.src = myChart.getDataURL({
type: 'png', // can be jpeg or png
pixelRatio: 5, // image's ratio. default is 1
backgroundColor: '#fff', // hex color defining the background of the chart
});
// just for sampling
// opening new tab
const imgTab = window.open('');
// rendering the base64 image retrieved
imgTab.document.write(`<img src='${img.src}'/>`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment