I would like to create a link to allow the user to download the displayed graph. The way i am currently trying to get it to work is with .toDataUrl
is that considered a safe way or is there another way of going about doing this.
HTML:
<canvas id="myChart" baseChart [colors]="colorsOverride" [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [legend]="barChartLegend"
[chartType]="barChartType" (chartHover)="chartHovered($event)" (chartClick)="chartClicked($event)">
</canvas>
<div class="footer">
<button (click)="exportGraph()">Export Graph</button>
</div>
Components:
export_graph = <HTMLCanvasElement>document.getElementById("myChart");
downloadLink: string;
exportGraph(){
this.downloadLink = this.export_graph.toDataURL("image/png");
}
When i try to export this is the error message i get in my console:
Cannot read property 'toDataURL' of null