Charts.js Truncation of Scale Labels

by Prabjot Singh

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<canvas id="myChart" width="400" height="200"></canvas>

JavaScript

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: 'line',
    data: {
      datasets: [{
                  backgroundColor: 'rgba(0,0,0,0)',
            borderColor: '#5ac3d0',
        label: 'MILESTONE',
        data: [{"x":"2016-12-16T18:30:00.000Z","y":50},{"x":"2017-03-16T18:30:00.000Z","y":53},{"x":"2017-06-16T18:30:00.000Z","y":56},{"x":"2017-09-16T18:30:00.000Z","y":59},{"x":"2017-12-16T18:30:00.000Z","y":62}]
      },{
                  backgroundColor: 'rgba(255, 99, 132, 0.2)',
            borderColor: 'rgba(255,99,132,1)',
      label: 'UPDATES',
      data: [{"x":"2017-01-16T18:30:00.000Z","y":51},{"x":"2017-02-16T18:30:00.000Z","y":52},{"x":"2017-03-16T18:30:00.000Z","y":53},{"x":"2017-04-16T18:30:00.000Z","y":54},{"x":"2017-05-16T18:30:00.000Z","y":55}]
      }]
    },
    options: {
      scales: {
        xAxes: [{
          type: 'time',
          time: {
            displayFormats: {
              'day': 'MMM DD, YY',
              'month': 'MMM DD, YY',
              'year': 'MMM DD, YY',
            },
            unit: 'month',
            tooltipFormat: 'MMM DD, YYYY'
          },
          position: 'bottom',
          scaleLabel: {
            display: true,
            labelString: 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout'
          }
        }],
        yAxes: [{
          scaleLabel: {
            display: true,
            labelString: 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout'
          }
        }]
      },
      elements: {
        line: {
          tension: 0
        }
      },
      legend: {
        display: true,
      },
      tooltips: {
        enabled: true,
        mode: "point"
      },
      hover: {
        mode: "point"
      }
    }
});