繁体   English   中英

当轴 position 居中时,ChartJS x 轴标题不可见

[英]ChartJS x axis title not visible when axis position is centered

当position不居中时,标题可见。 x轴不居中

但是如果 x 轴 position 居中,标题就会消失。 位置中心

这是我的 Chartjs 选项。文档似乎没有解决此问题的可行选项。

const options = {
    maintainAspectRatio: false,

    scales: {
      x: {
        type: 'linear',
        min: 0,
        max: MAX_AGE,
        grid: {
          display: false,
        },
        title: {
          display: true,
          text: 'xaxis title',
        },
        position: 'center', // what can I do to view the x-axis tile when axis is centered.
      },
      y: {
        min: -10,
        max: 10,
        grid: {
          display: false,
        },
        title: {
          display: true,
          text: 'yaxis title',
        },
      },
    },
}

我假设您使用的是 chart.js 的版本低于 3.5,因为这是一个已在 3.5 版本中通过此 pr 解决的错误: https://github.com/chartjs/Chart.js/pull/9413

因此,要解决您的问题,您需要更新到最新版本的 chart.js

图表标题选项在 Chartjs 的 v2 中也有了很大的发展。 我发现标题完全隐藏,直到我添加填充 - 例如

options: {
      plugins: { 
        title: {
          display: true, 
          text: "Title" ,
          padding: {
              top: 10,
              bottom: 10
          },
          font: {
            size: 24,
            style: 'italic',
            family: 'Helvetica Neue'
          }
        }
      },
      ... other options here
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM