我第一次使用“ swimlane / ngx-charts”,我想显示从其余调用中获取的数据。当我对数据进行硬编码时可以使用,否则不能使用
代码HTML:
<ngx-charts-line-chart
[scheme]="lineChartColorScheme"
[results]="dashBoardData"
[gradient]="lineChartGradient"
[xAxis]="lineChartShowXAxis"
[yAxis]="lineChartShowYAxis"
[legend]="true"
[showXAxisLabel]="lineChartShowXAxisLabel"
[showYAxisLabel]="lineChartShowYAxisLabel"
[xAxisLabel]="lineChartXAxisLabel"
[yAxisLabel]="lineChartYAxisLabel"
[autoScale]="lineChartAutoScale"
(select)="onSelect($event)">
</ngx-charts-line-chart>
我的服务:
getDashboardStatusData(groupName: any, status: any): Promise <any> {
return this.http.get('/nysohqcetm/dashboard/lineChart/status?group='+groupName+'&status='+ status).
toPromise().then(this.extractData).catch(this.handleError);
}
private extractData(res: Response) {
let body = res.text();
return res.text();
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
我的组件:
this.qceHomeComponentService.getDashboardStatusData('any', 'Unassigned').then(result => {
console.log(result);
this.dashBoardDataAssigned.push(result);
}).catch(error => console.log(error));
以上代码未在图形上显示数据。以上服务调用返回json数据。如果我将相同的json数据硬编码到数组中并将其绑定到结果,则图将出现
dashBoardDataAssigned = [
{
"name":"Unassigned",
"series": [
{"name":"17-Sep-2018","value":2000},
{"name":"18-Sep-2018","value":1550},
{"name":"19-Sep-2018","value":1175},
{"name":"20-Sep-2018","value":725},
{"name":"21-Sep-2018","value":300}
]
}
];
我尝试通过承诺和可观察的方式使用它,长期以来都面临着同样的问题。有人可以帮我吗?