我ng2-charts
正在开发我的 Angular-cli 构建应用程序。我很新,所以任何帮助表示赞赏。我在 Firebase 上有数据设置。我在服务中创建了一个方法来访问该数据,并且当我使用此代码时
getGraphData():Observable<any>{
var graphData$ = this.af.database.list(`graphdata/${this.uid}`)
.map(tspa => tspa.map(tpa => tpa.$value))
.do(console.log);
graphData$.subscribe();
return Observable.of([]);
}
控制台记录正确的数据。
前任。[1000, 5000, 2000]
问题是当我更改方法以返回结果时,如下所示:
getGraphData():Observable<any>{
return this.af.database.list(`graphdata/${this.uid}`)
.map(tspa => tspa.map(tpa => tpa.$value))
}
并尝试将其分配给组件中的变量。我总是得到以下控制台日志:
>FirebaseListObservable
我已经看到了不同的方法来获得我想要的结果,例如使用flatMap
,Observable.combineLatest()
但我无法获得任何其他结果。我有 json 数据,我想将其作为数组分配给一个变量,以便在我的条形图中显示它。
图.ts
data$: any;
form$: any;
public barChartLabels:string[] = ['Account1', 'Account2', 'Account3', 'Account4', 'Account5', 'Account6', 'Account7'];
public barChartType:string = 'bar';
public barChartLegend:boolean = true;
firstVar:any = [28, 48, 40, 19, 86, 27, 90];
secondVar:any = [28, 48, 40, 19, 86, 27, 90];
public barChartData:any[] = [
{data: this.firstVar, label: 'Series A'},
{data: this.secondVar, label: 'Series B'}
];
我想分配firstVar
新的 Firebase 数据。有什么建议么?
我通常访问这样的方法:
ngOnInit() {
this.firstVar = this.transactionsS.getGraphData();
console.log(this.firstVar)
}
updateGraph(){
this.firstVar = this.transactionsS.getGraphData()
console.log(this.firstVar)
}