echarts导出图片

Echarts 导出图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
downCharts () {
let baseURL
if (this.btShow) {
baseURL = this.$refs.pie.getImageBase()
} else {
baseURL = this.$refs.bar.getImageBase()
}
const elink = document.createElement('a');
elink.download = '统计图';
elink.style.display = 'none';
elink.href = baseURL;
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink)
}



getImageBase () {
return this.myChart.getDataURL({
type: 'png',
pixelRatio: 1.5, //放大两倍下载,之后压缩到同等大小展示。解决生成图片在移动端模糊问题
backgroundColor: '#fff'
})
}