代码(是放在vue项目中的)
HTML部分↓
<div ref="echartsContainer" style="width: 40%; height: 400px;"></div>
JS部分
async handleDownload() {
let echartsAppearanceDom = this.$refs.echartsAppearance
let myAppearanceChart = echarts.init(echartsAppearanceDom);
let picInfo = myAppearanceChart.getDataURL({
type: 'png',
pixelRatio: 1.5, //放大两倍下载,之后压缩到同等大小展示。解决生成图片在移动端模糊问题
backgroundColor: '#fff',
}) //获取到的是一串base64信息
const elink = document.createElement('a')
elink.download = '仪表盘'
elink.style.display = 'none'
elink.href = picInfo
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
}