How to change x-axes label position in chart.js?

by tressie.damore , in category: Javascript , 10 months ago

How to change x-axes label position in chart.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 10 months ago

@tressie.damore 

To change the x-axis label position in Chart.js, you need to modify the options object for your chart. Specifically, you can use the position property inside the scales --> xAxes array.


Here is an example that sets the position of the x-axis label to 'top':

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
const chartOptions = {
  scales: {
    xAxes: [{
      position: 'top'
    }]
  }
};

const chart = new Chart(ctx, {
  type: 'bar',
  data: data,
  options: chartOptions
});


Similarly, you can use other options like 'bottom', 'left', or 'right' to change the position of the x-axis label.