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', width: 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', width: 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', width: 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', width:4 } }, symbolSize:12 }, ] }; this.myChart.setOption(option, true);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2017-05-02 webpack命令