1、按钮点击之后
const clickA =() =>{
const countPieDwlx = echarts.init(document.getElementById(chartId)?.firstChild as HTMLElement);
countPieDwlx?.setOption(option);
countPieDwlx?.resize();
savePieImg(countPieDwlx, cellId)
}
下载图片方法
function savePieImg(countPieDwlx, cellId) {
var picInfo = countPieDwlx.getDataURL({
type: 'png',
pixelRatio: 1.5, //放大两倍下载,之后压缩到同等大小展示。解决生成图片在移动端模糊问题
backgroundColor: '#fff'
});//获取到的是一串base64信息
const elink = document.createElement('a');
elink.download = "趋势图" + cellId;
elink.style.display = 'none';
elink.href = picInfo;
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink)
}
over~