TypeError: Cannot read property 'length' of undefined - ngx-charts-bar-vertical-stacked
TypeError: Cannot read property 'length' of undefined - ngx-charts-bar-vertical-stacked
我正在尝试使用 angular 图表 (ngx-charts-bar-vertical-stacked) 在堆叠垂直条形图中显示计数报告,但出现以下错误:
动态构建数据,例如
//app.ts 我声明
array chartDataNGX:any[];
然后在构造函数中调用 getChatrtData()
然后在 getchartdata 中我会做类似
this.chartDataNGX.push(
{"name": "TEST2","series": [
{"name": "Target","value": 40632},
{"name": "Actual","value": 36953},
{"name": "Projected","value": 31476}
]},
{"name": "TEST3","series": [
{"name": "Target","value": 40632},
{"name": "Actual","value": 36953},
{"name": "Projected","value": 31476}
]
});
失败并显示“无法读取未定义的 属性 'length'”,那么我做错了什么?
请帮忙。
如果结果为空,请尝试使用 ngIf 避免制作图表
<div *ngIf="chartDataNGX.length">
<ngx-charts-bar-vertical-stacked
[view]="view"
[scheme]="colorScheme"
[results]="chartDataNGX"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
</ngx-charts-bar-vertical-stacked>
</div>
通常我们在构造函数中初始化变量,并在ngOnInit
生命周期钩子
中完成方法
我正在尝试使用 angular 图表 (ngx-charts-bar-vertical-stacked) 在堆叠垂直条形图中显示计数报告,但出现以下错误:
动态构建数据,例如 //app.ts 我声明
array chartDataNGX:any[];
然后在构造函数中调用 getChatrtData()
然后在 getchartdata 中我会做类似
this.chartDataNGX.push(
{"name": "TEST2","series": [
{"name": "Target","value": 40632},
{"name": "Actual","value": 36953},
{"name": "Projected","value": 31476}
]},
{"name": "TEST3","series": [
{"name": "Target","value": 40632},
{"name": "Actual","value": 36953},
{"name": "Projected","value": 31476}
]
});
失败并显示“无法读取未定义的 属性 'length'”,那么我做错了什么?
请帮忙。
如果结果为空,请尝试使用 ngIf 避免制作图表
<div *ngIf="chartDataNGX.length">
<ngx-charts-bar-vertical-stacked
[view]="view"
[scheme]="colorScheme"
[results]="chartDataNGX"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
</ngx-charts-bar-vertical-stacked>
</div>
通常我们在构造函数中初始化变量,并在ngOnInit
生命周期钩子