導出原理:
得到Echarts畫出的canvas圖片的base64,將其導出
代碼:
<el-button type="primary" @click="downLoad">導出</el-button>
<div id="volume"></div>
downLoad(){
var myChart = echarts.init(document.getElementById('volume'))
var resultBase64 = myChart.getDataURL({
type: 'png',
pixelRatio: 2, //放大兩倍下載,之後壓縮到同等大小展示。解決生成圖片在移動端模糊問題
backgroundColor: '#fff' //設置導出圖片的背景顏色
})
var $a = document.createElement('a');
$a.setAttribute("href", resultBase64);
$a.setAttribute("download", "");
$a.click();
}
Echarts圖表如何繪製,看這兒
https://blog.csdn.net/weixin_40970987/article/details/82457486