微信小程序解决echarts图表不清晰的问题
2021-12-20 本文已影响0人
ERROR505
原文链接:https://blog.csdn.net/weixin_43985637/article/details/105242537
1.获取设备的像素
const getPixelRatio = () => {
let pixelRatio = 0
wx.getSystemInfo({
success: function (res) {
pixelRatio = res.pixelRatio
},
fail: function () {
pixelRatio = 0
}
})
return pixelRatio
}
2.初始化图表的时候设置像素比
devicePixelRatio
//获取像素比
const getPixelRatio = () => {
let pixelRatio = 0
wx.getSystemInfo({
success: function (res) {
pixelRatio = res.pixelRatio
},
fail: function () {
pixelRatio = 0
}
})
return pixelRatio
}
// console.log(pixelRatio)
var dpr = getPixelRatio()
// 初始化图表
const chart = echarts.init(canvas, null, {
// renderer: 'svg',//微信小程序中不支持该设置
width: width,
height: height,
devicePixelRatio: dpr
});
setOption(chart,this);