uniapp 移动端axisLabel 设置formatter无效的解决方法

发布时间 2023-07-30 15:56:58作者: 环岛公路

pc端是直接在option里配置

移动端在renderjs里的监听变化的时候去设置

updateEcharts(newValue, oldValue, ownerInstance, instance) {
                // 监听 service 层数据变更
                try {
                    newValue.xAxis.axisLabel.formatter = function(val) {
                      return val.replace(' ', '\n')    //x轴的数据有空格就换行
                    }
                    newValue.yAxis.axisLabel.formatter = function(val) {
                      return val.toFixed(1)  //y轴始终保留小数点一位
                    }
                                        
                    myChart.setOption(newValue)
                } catch (error) {}
            }