#echarts chart to Base64 method

#echarts chart generation Base64 method

First find the chart hosting container

For example

<div style="height: 100%;width:100%" id="fixed"></div>

I encapsulated a method of converting to base64:

/*
    echarts图转base64
    ele 图表DOM 容器ID   对应例子的ID("#fixed")
 */
function createBase64(ele) {
    
    
    let docEle = ele + " canvas";
    let canvasFixed = document.querySelector(docEle),//获取图表元素
        canvasWidth = canvasFixed.width,//获取图表元素宽度
        canvasHeigth = canvasFixed.heigth,//获取图表元素高度
        canvas2D = canvasFixed.getContext('2d');
    canvas2D.drawImage(canvasFixed,canvasWidth,canvasHeigth);
    return canvasFixed.toDataURL()
}



let echartsBase64 = createBase64("#fixed");
	console.log(echartsBase64)

The effect is shown in the figure: Chart to base64 console output
)(https://imgtu.com/i/4FdKij#pic_center)]

After copying it, you can put it in the browser or parse the base64 website to check whether it is ok:

Base64 is placed in the browser and opened directly

Once you get it, you can do what you want to do;

Note that you must wait until the echarts graph is loaded before executing it;

Guess you like

Origin blog.csdn.net/weixin_45385944/article/details/120281940