Echarts柱状图格式化Label
1. y轴数值过大时,显示效果不佳,需要除以10000后拼接“万”即可;
2. 上代码:
axisLabel: {
textStyle: {
color: '#999'
},
// margin: 2,
formatter: function (value, index) {
if (value >= 10000 && value < 10000000) {
value = value / 10000 + "万";
} else if (value >= 10000000) {
value = value / 10000000 + "千万";
}
return value;
}
}
柱状图上的数据也可进行格式化:
series: [{
data: [],
type: 'line',
smooth: true,
barMaxWidth: 30,
areaStyle: {},
label: {
show: true,
rotate: 0,
position: 'top',
distance: 10,
textStyle: { // 数值样式
color: 'black',
fontSize: 12,
},
formatter: function (value) {
var val = value.data;
if (val >= 10000 && val < 10000000) {
val = (val / 10000).toFixed(2) + "万";
}
return val;
}
},
itemStyle: {
normal: {
// barBorderRadius: [10, 10, 0, 0],
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1,
[
{offset: 0, color: '#2E91DE'},
{offset: 0.5, color: '#70B5EB'},
{offset: 1, color: '#CEE8FD'}
]
)
}
}
}]
效果图: