【发布时间】:2019-04-30 17:38:00
【问题描述】:
我正在尝试为ng2-charts 中的折线图应用渐变色。但我收到错误
ERROR TypeError: Cannot read property 'nativeElement' of undefined
代码
<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
}
];
【问题讨论】:
标签: angular ng2-charts