zoukankan      html  css  js  c++  java
  • echarts移动端字体模糊解决方法

    echarts使用canvas画图,在移动端使用rem时候,若viewport的scale被缩放,则字体会发生模糊,本人采用的解决方法是在不同的dpr下使用不同的字体大小,具体代码如下:

    获取字体大小,实测在主流手机上效果尚可:

    function fGetChartFontSize(){
        const dpr = window.devicePixelRatio;
        let fontSize = 14;
        if(dpr == 2){
            fontSize = 19;
        }
        else if(dpr == 3){
            fontSize = 30;
        }
        else if(dpr > 3){
            fontSize = 30;
        } 
        return fontSize;
    }

    设置echarts的字体大小

    const size = fGetChartFontSize();
    const option = {
        tooltip: {
            show: true,
            trigger: 'axis',
            formatter: "{c}%",
            backgroundColor: '#f46200',
            axisPointer: {
                lineStyle: {
                    show: true,
                    color: '#f46200',
                     1, 
                }
            },
            textStyle:{
                fontSize:size //此处设置提示文字大小
            },
            padding:[5,10]
        },
        grid: {
            top: '10%',
            left: '0%',
            right: '5%',
            bottom: '0%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            data: this.dateList,
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#d2d2d2',
                    fontSize: size //此处设置X轴文字大小
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#e5e5e5',
                     1, 
                }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#e5e5e5'
                }
            }
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#d2d2d2',
                    fontSize: size, //此处设置Y轴文字大小
                    baseline:'bottom'
                }
            },
            max: 4.9,
            min: 3.7,
            interval: 0.2,
            axisLine: {
                lineStyle: {
                    color: '#e5e5e5',
                     1, 
                }
            },
            splitLine: {
                lineStyle: {
                    color: '#e5e5e5'
                }
            }
        }],
        series: [{
            name: '',
            type: 'line',
            stack: '总量',
            areaStyle: {
                normal: {}
            },
            data: this.rateList,
            itemStyle: {
                normal: {
                    borderColor: '#f46200',
                }
            },
            areaStyle: {
                normal: {
                    color: '#ffe1c2',
                }
            },
            lineStyle: {
                normal: {
                    color: '#ff8200',
                    4
                }
            },
            symbolSize:12
        },
    
        ]
    };
    
    this.myChart.setOption(option, true);
  • 相关阅读:
    【leetcode】11. 盛最多水的容器
    【leetcode】8. 字符串转换整数 (atoi)
    【leetcode】6. Z 字形变换
    【leetcode】5. 最长回文子串
    【leetcode】LCP 19. 秋叶收藏集
    删除第一个节点问题
    问一个大学学习计算机这门专业的问题
    Struts文件上传页面上传后显示“连接已重置”
    2013-12-6 思杨没吃饱 饿醒了
    2013-12-7 snoopy乐园中的思杨
  • 原文地址:https://www.cnblogs.com/mengff/p/8980814.html
Copyright © 2011-2022 走看看