簡體   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