Search code examples
typescriptchart.jsaurelia

Getting the postion of the y-axis labels in chartJS


I have a ChartJS area and sometimes the data is so much that the y-axis labels are slanted. I have two issues with this.

  1. How can we make it go 100% vertical so I can increase the grid lines and they don't overlap?
  2. How do I get the bottom point of the label?

For the label point, I am able to get the y-axis bottom point like so:

 const yBottom = chart.scales['y-axis-0'].bottom;

I have the following screencap:

enter image description here

I want to get the bottom of that label.


Solution

  • You can make x-axis tick labels 100% vertical by defining option scales.x.ticks.minRotation: 90.

    options: {
      scales: {
        x: {
          ticks: {
            minRotation: 90
          }
        }
      }
    }
    

    For further information, please consult Tick Configuration from the Chart.js documentation.