微信小程序

微信小程序 解决echarts模糊问题

2022-03-24  本文已影响0人  AAA_si

在上篇微信小程序 echarts统计图中提示过devicePixelRatio可以解决小程序视图模糊的问题

首先获取设备像素值
//获取像素比
const getPixelRatio = () => {
    let pixelRatio = 0
    wx.getSystemInfo({
        success: function (res) {
            pixelRatio = res.pixelRatio
        },
        fail: function () {
            pixelRatio = 0
        }
    })
    return pixelRatio
}
var dpr = getPixelRatio()
// 上述代码是wx获取设备的像素值 dpr

// 初始化图表
const chart = echarts.init(canvas, null, {
        // renderer: 'svg',//微信小程序中不支持该设置
        width: width,
        height: height,
        devicePixelRatio: dpr   // 获取到的像素值赋值给devicePixelRatio, 在echarts中必写
});
setOption(chart,this);
上一篇 下一篇

猜你喜欢

热点阅读