[Chartjs]-Chart.js not showing up on online site

2👍

Bit late but I had the same problem. To fix it you need to get your chart to generate from window.onload.

e.g.

window.onload = function() {
  var ctx = document.getElementById('myChart').getContext('2d');
  window.myLine = new Chart(ctx, {
      type: 'line',
      data: {
          labels: ["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"],
          datasets: [{
              label: 'Udvikling i motorvejstrafikken 2010-2017',
              data: [100, 103.5, 107.2, 110.3, 115.4, 120.9, 126.3, 131.5],
              backgroundColor: [
                  'rgba(255, 99, 132, 0.2)',
                  'rgba(54, 162, 235, 0.2)',
                  'rgba(255, 206, 86, 0.2)',
                  'rgba(75, 192, 192, 0.2)',
                  'rgba(153, 102, 255, 0.2)',
                  'rgba(255, 159, 64, 0.2)'
              ],
              borderColor: [
                  'rgba(255,99,132,1)',
                  'rgba(54, 162, 235, 1)',
                  'rgba(255, 206, 86, 1)',
                  'rgba(75, 192, 192, 1)',
                  'rgba(153, 102, 255, 1)',
                  'rgba(255, 159, 64, 1)'
              ],
              borderWidth: 4
          }]
      },
      options: {
          scales: {
              yAxes: [{
                  ticks: {
                      min: 90
                  }
              }]
          }
      }
  });
};

Don’t know why it works locally without this, but needed this change to display on the server.

Leave a comment