1 使用详解
yAxis.axisLabel.formatter
说明:刻度标签的内容格式器,支持字符串模板和回调函数两种形式。
默认:'{value} '。
参数类型:string,Function
可选值:请参考以下博客。
ECharts formatter属性设置3种方式(字符串模板,函数模板,回调函数)
2 原始效果图
3 实现代码
3.1 实现代码(字符串模板)
var option = {
title: {
text: '第一个 ECharts 实例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"],
boundaryGap: false,//x轴两边不留空白
},
yAxis: {
type:"value",
axisLabel:{
formatter:"{value}件"//字符串模板
}
},
series: [{
name: '销量',
type: 'line',
data: [5, 20, 36, 10, 10, 20]
}]
};
3.2 实现代码(函数模板)
var option = {
title: {
text: '第一个 ECharts 实例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["1月","2月","3月","4月","5月","6月"],
boundaryGap: false,//x轴两边不留空白
},
yAxis: {
type:"value",
axisLabel:{
//函数模板
formatter:function (value, index) {
var result="";
switch(value){
case 1:result="Ⅰ类";break;
case 2:result="Ⅱ类";break;
case 3:result="Ⅲ类";break;
case 4:result="Ⅳ类";break;
case 5:result="Ⅴ类";break;
default:"-";
}
return result;
}
}
},
series: [{
name: '类别',
type: 'line',
data: [5, 2, 3, 1, 4, 2]
}]
};