ChartJS 我怎样才能删除数据和y轴上隐藏的刻度之间的左间距

628mspwn  于 2023-04-06  发布在  Chart.js
关注(0)|答案(1)|浏览(241)

问题的图像

如图所示,隐藏y轴上的刻度和边框后,数据左侧仍有我想删除的填充。
我使用的版本:chart.js@4.2.1
我尝试了以下方法:

  1. #potential solution 1
  2. layout: {
  3. padding: {
  4. left: -10
  5. }
  6. },
  7. #potential solution 2
  8. ticks: {
  9. padding: 0,
  10. backdropPadding: 0
  11. },
  12. #potential solution 3
  13. scales: {
  14. x: {
  15. afterFit: scale => {
  16. scale.paddingLeft -= 3
  17. scale.paddingRight -= 3
  18. }
  19. }
  20. }
lawou6xi

lawou6xi1#

我认为你可以将align选项设置为X轴上的刻度。

  1. x: {
  2. ticks: {
  3. align: 'inner'
  4. }
  5. },

参见文档:https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#common-tick-options-to-all-cartesian-axes

相关问题