You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Apache ECharts中反转y轴且不移动x轴?

解决ECharts仅反转Y轴不移动X轴的问题

要实现仅反转Y轴(让100在底部、0在顶部)同时保持X轴在底部,只需要在**xAxis配置中手动指定position: 'bottom'**即可,强制固定X轴的位置,避免随Y轴反转被带至顶部。

修改后的完整配置代码如下:

const options = {
  xAxis: {
    data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    type: 'category',
    name: 'Date',
    position: 'bottom' // 新增:固定X轴在底部
  },
  yAxis: { min: 0, max: 100, inverse: true, type: 'value', name: 'Rank' },
  series: [
    {
      data: [10, 80, 28, 55, 19],
      type: 'line',
      smooth: true,
      lineStyle: {
        width: 3,
      },
    },
  ],
  tooltip: {
    show: true,
    trigger: 'item',
  },
  grid: {
    left: 50,
    top: 50,
    right: 50,
    bottom: 50,
  },
}

原理说明:当开启Y轴的inverse: true时,ECharts会默认调整坐标轴的相对布局逻辑,导致X轴跟随移动。通过显式指定X轴的position属性,就能覆盖默认的布局行为,让X轴始终固定在底部,同时Y轴保持反转状态。

内容的提问来源于stack exchange,提问作者TinyTiger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 15:09:12