Chartjs-Chart js: Y axis labels with carriage return on a row with multiple horizontal bars

0👍

You will need to use a labels array and place all the multiline labels in an array where each entry is its own line:

const options = {
  type: 'bar',
  data: {
    labels: [
      ['hello', 'world'],
      ['test', 'second line'], 'ff'
    ],
    datasets: [{
      label: '# of Votes',
      data: [5, 3, 6],
      borderWidth: 1
    }, ]
  },
  options: {
    indexAxis: 'y',
    scales: {}
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.3.0/chart.umd.js"></script>

<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>

Leave a comment