在 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函数将文字的每个字符之间添加换行符,这样就能够让文字居右显示了。

ECharts 柱形图 x 轴文字居右显示技巧 - 使用 formatter 函数