ECharts 柱形图 x 轴文字居右显示技巧 - 使用 formatter 函数
在 ECharts 的柱形图中,x 轴文字默认是居中显示的。如果想要将文字居右显示,可以使用formatter属性来自定义 x 轴的文字显示方式。
以下是修改后的代码:
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: ['Monxxxxxxxxxx', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
},
axisLabel: {
rotate: '45',
formatter: function(value) {
return value.split("").join("\n"); // 将文字每个字符之间添加换行符
}
}
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: 'Direct',
type: 'bar',
barWidth: '60%',
data: [10, 52, 200, 334, 390, 330, 220]
}
]
};
使用formatter函数将文字的每个字符之间添加换行符,这样就能够让文字居右显示了。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qukv 著作权归作者所有。请勿转载和采集!