echarts文字随页面缩放

943 阅读1分钟

1.在utils文件夹中新建index.js

image.png

/**
 * echart 窗口---自适应字体
 * @param res
 * @returns {number}
 */
export const echartfontSize = (res) => {
    let docEl = document.documentElement,
        clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (!clientWidth) return;
    let fontSize = 100 * (clientWidth / 1920);
    //  console.log(res * fontSize, 'res * fontSize')
    return res * fontSize

}

使用: 在页面中引入

import { echartfontSize } from "@/utils";

image.png