echarts 图表是用svg渲染的,所以需要获取svg标签的内容即可
const svg = this.$refs.barchart.getElementsByTagName("svg")[0];
const echartsSvg = svg.outerHTML;
//SVG转Base64
const svgString = echartsSvg; // 这里填入你的SVG字符串
const svgBlob = new Blob([svgString], { type: "image/svg+xml" });
const _this1 = this;
// 使用 FileReader 读取 Blob,并在完成时生成 base64 字符串
let reader = new FileReader();
reader.onload = function () {
const base64data = reader.result;
// 使用base64data进行后续操作
let imgSrc = base64data;
};
reader.readAsDataURL(svgBlob);