Chartjs-Unable to clone a Chart.js chart in a pop up

0👍

You can use JavaScript to achieve this:
Working sample: https://stackblitz.com/edit/angular-playground-i6sycz?file=app/hello-framework/hello-framework.component.ts

openChart(){
  var canvas = <HTMLCanvasElement>document.getElementById("amplitudeChart");
  let canvasClone = this.cloneCanvas(canvas);
  console.log(canvasClone)
  var myWindow = window.open();
  myWindow.document.body.appendChild(canvasClone);
}

cloneCanvas(oldCanvas) {

    //create a new canvas
    var newCanvas = document.createElement('canvas');
    var context = newCanvas.getContext('2d');

    //set dimensions
    newCanvas.width = oldCanvas.width;
    newCanvas.height = oldCanvas.height;

    //apply the old canvas to the new one
    context.drawImage(oldCanvas, 0, 0);

    //return the new canvas
    return newCanvas;
}

Leave a comment