score:15

Accepted answer

You can use the following chart plugin :

plugins: [{
   beforeInit: function(chart) {
      chart.data.labels.forEach(function(e, i, a) {
         if (/\n/.test(e)) {
            a[i] = e.split(/\n/);
         }
      });
   }
}]

add this followed by your chart options

ᴜꜱᴀɢᴇ :

add a new line character (\n) to your label, wherever you wish to add a line break.

ᴅᴇᴍᴏ

var chart = new Chart(ctx, {
   type: 'horizontalBar',
   data: {
      labels: ['Jan\n2017', 'Feb', 'Mar', 'Apr'],
      datasets: [{
         label: 'BAR',
         data: [1, 2, 3, 4],
         backgroundColor: 'rgba(0, 119, 290, 0.7)'
      }]
   },
   options: {
      scales: {
         xAxes: [{
            ticks: {
               beginAtZero: true
            }
         }]
      }
   },
   plugins: [{
      beforeInit: function(chart) {
         chart.data.labels.forEach(function(e, i, a) {
            if (/\n/.test(e)) {
               a[i] = e.split(/\n/);
            }
         });
      }
   }]
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

score:19

If you want to have full control over how long labels are broken down across lines you can specify the breaking point by providing labels in a nested array. For example:

var chart = new Chart(ctx, {
...
  data: {
    labels: [["Label1 Line1:","Label1 Line2"],["Label2 Line1","Label2 Line2"]],
    datasets: [{
...
});

Related Query

More Query from same tag