I am trying to apply gradient color for line chart in ng2-charts. But I am getting error
ERROR TypeError: Cannot read property 'nativeElement' of undefined
Code
<canvas #myCanvas [colors]="lineChartColors" ...
export class Demo {
@ViewChild("myCanvas") canvas: ElementRef;
lineChartColors;
// in ngOnInit
let gradient = this.canvas.nativeElement.getContext('2d').createLinearGradient(0, 0, 0, 200);
gradient.addColorStop(0, 'green');
gradient.addColorStop(1, 'white');
this.lineChartColors = [
{
backgroundColor: gradient
}
];