简体   繁体   中英

ChartJS x axis title not visible when axis position is centered

When position is not centered, the title is visible. x轴不居中

But the title disappears, if the x-axis position is centered. 位置中心

Here is my Chartjs options.The documentation doesn't seem to have viable options to address this issue.

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',
        },
      },
    },
}

I assume you are using a version of chart.js lower as 3.5 since this was a bug that has been resolved in the 3.5 release with this pr: https://github.com/chartjs/Chart.js/pull/9413

So to resolve your issue you will need to update to the latest version of chart.js

The Chart Title options have evolved quite a bit in v2 of Chartjs as well. I found that the title was hidden entirely until I added padding - for one example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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