先看看效果图
这个我是指定Y轴只有五个分段,并且自定义显示名称具体代码如下
let that = this;
yAxis: {
type: "value",
min: 0, // 刻度最小值
max: 4, // 刻度最大值(需要动态获取最大值,并且能被3整除(向下取整再乘回来))
splitNumber: 4, // 横线数
interval: 1, // 刻度间隔
splitLine: {
//网格线
show: true,
lineStyle: {
// 使用深浅的间隔色
color: "#CAE6FE",
type: "dashed",
},
width: 1,
},
axisLine: {
//y轴
show: true,
lineStyle: {
color: "#CAE6FE", // x轴线
width: 1,
},
},
axisLabel: {
interval: 0,
formatter: function (params) {
return that.getLeaves(params);
},
textStyle: {
color: "#333333",
},
},
},
注:
我这里自定义y轴刻度,因为后台返的等级的ABCD这样,图表无法识别,所以我用getLeave给他转译成数字对应1234,这样Y轴刻度就可以正常绘制了,显示的时候再用getLeaves反转一下,显示成需要显示的数据ABCD这样就完成了正常显示,也就是自定义Y轴刻度显示。
这里是方法
getLeaves(leave) {
switch (leave) {
case 4:
return "A级";
case 3:
return "B级";
case 2:
return "C级";
case 1:
return "D级";
case 0:
return "未评价";
default:
return "未评价";
}
},
getLeave(leave) {
switch (leave) {
case "A级":
return 4;
case "B级":
return 3;
case "C级":
return 2;
case "D级":
return 1;
case "未评价":
return 0;
default:
return 0;
}
},
好了以上是本次学习内容,学废了吗,家人们!