Chartjs-OffsetWidth / offsetHeight is zero when template loaded by ngRoute

0👍

I resolved the issue by recreating the canvas on each controller’s initialization. I didn’t try the solution posted by @bviale:

getChartContext = function(id, width, height) {
  var canvas = document.getElementById(id);
  var canvasParent = canvas.parentNode;
  canvas.remove();
  canvas = document.createElement("canvas");
  canvas.id = id;
  canvas.width = width;
  canvasParent.appendChild(canvas);
  var ctx = canvas.getContext('2d');
  return ctx;
};

Leave a comment