Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:13
Show Gist options
  • Save arturovt/39649f21aec371c822088c5a1b59f852 to your computer and use it in GitHub Desktop.
Save arturovt/39649f21aec371c822088c5a1b59f852 to your computer and use it in GitHub Desktop.
import { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core';
import * as Chart from 'chart.js';
@Component({
selector: 'app-line-chart',
template: `
<canvas #canvas></canvas>
`
})
export class LineChartComponent implements OnInit {
@ViewChild('canvas')
public canvas: ElementRef<HTMLCanvasElement> = null;
private options = {
...
};
constructor(private zone: NgZone) {}
public ngOnInit(): void {
const ctx = this.canvas.nativeElement.getContext('2d');
this.zone.runOutsideAngular(() => {
new Chart(ctx, this.options); // GOOD!
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment