一 效果截图
二 上代码
xAxis: {
type: 'category',
boundaryGap: false,
data: ["2018/07", "2018/08", "2018/09", "2019/10", "2019/11", "2019/12", "2020/01", "2020/02", "2020/03"].map((item) => {
let front = item.substring(0, 4)
let end = item.substring(item.length - 2)
if(this.yearStash == front) {
return `\n\n\n${end}`
}else {
this.yearStash = front
return `\n${front}\n\n${end}`
}
})
},
我是处理x轴日期,一般拿到的都是数组substring就是截取年月, 定义一个yearStash的变量存年份, 写一个判断如果相同年份就不展示, 不同的年份展示,完美解决,此方法还可以举一反三
加油 爱分享