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

如何将图表的X轴设置在顶部?附配置代码求助

横向柱状图X轴移至顶部的解决方法

当前图表:
当前图表

期望效果:
期望图表

现有配置代码:

borderSkipped: false,
indexAxis: 'y',
// aspectRatio: 4,
scales: {
  y: {          
    beginAtZero: true
    // suggestedMax: 24,          
  },
  x: {          
    suggestedMax: 24,          
    ticks: {
      stepSize: 1            
    }
  }        
}

只需在scales.x配置里新增position: 'top'属性,就能把X轴移到顶部。修改后的代码如下:

borderSkipped: false,
indexAxis: 'y',
// aspectRatio: 4,
scales: {
  y: {          
    beginAtZero: true
    // suggestedMax: 24,          
  },
  x: {          
    position: 'top', // 将X轴设置在顶部
    suggestedMax: 24,          
    ticks: {
      stepSize: 1            
    }
  }        
}

因为你设置了indexAxis: 'y',图表为横向柱状图,此时X轴是数值轴,默认位于底部,添加position: 'top'即可调整到顶部,完全匹配你的期望效果。

内容的提问来源于stack exchange,提问作者노재현

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 19:35:20