[Chartjs]-Label too long in yAxis with chartJs

3👍

You can break the string over multiple lines. This is done by splitting the string into an array. Chart.js parses each array element as a single line.

Example:

let labels = [
    ['this is a very long label', 'broken across two lines'],
    'short label'
  ],
  myBarChart = new Chart(document.getElementById('chart'), {
    type: 'horizontalBar',
    data: {
      labels: labels,
      datasets: [{
        label: 'Series1',
        data: [1, 1]
      }]
    },
    options: {
      maintainAspectRatio: false
    }
  });
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
<canvas id="chart"></canvas>

Leave a comment