Echarts解决默认单位为PX
在使用echarts绘制图表时,遇到不适配不同大小的屏幕的问题,这是因为echarts默认的单位为px,我们可以采用类似于rem的单位来实现一定程度的大小屏适配。
方法
这个方法是在网上找的,亲测有效。
adjustSize(res) {let docEl = document.documentElement,clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;if (!clientWidth) return;let adjustSize= 100 * (clientWidth / 1920);return res * adjustSize;},
使用此方法代替默认单位
配置项option中:
fontSize: this.adjustSize(0.12),
padding: [0, this.fontSize(0.2), 0, 0]
默认单位均可使用这个方法代替
当然要添加监听事件重绘才能实现
记录一下遇到的问题
Echarts解决默认单位为PX
在使用echarts绘制图表时,遇到不适配不同大小的屏幕的问题,这是因为echarts默认的单位为px,我们可以采用类似于rem的单位来实现一定程度的大小屏适配。
方法
这个方法是在网上找的,亲测有效。
adjustSize(res) {let docEl = document.documentElement,clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;if (!clientWidth) return;let adjustSize= 100 * (clientWidth / 1920);return res * adjustSize;},
使用此方法代替默认单位
配置项option中:
fontSize: this.adjustSize(0.12),
padding: [0, this.fontSize(0.2), 0, 0]
默认单位均可使用这个方法代替
当然要添加监听事件重绘才能实现
记录一下遇到的问题