Created
June 6, 2019 23:13
-
-
Save arturovt/39649f21aec371c822088c5a1b59f852 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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