从图表的方法获取值

问题描述 投票:0回答:1

我正在尝试从方法中获取值并将其用于图形但是当我尝试获取值时,它显示为null。

TS

`bgs= [];

 getbgs() {
  this.bgsService.getbgss(this.token).subscribe(
  data => {
   this.bgs = data.map(k => k.bgs);
 console.log(this.bgs);   // I can get the value here      
  }
 );
 }

 public lineChartData: Array<any> = [
  { data: [this.bgs], label: 'Series A' },
console.log("chart:" + this.bgs) // here the bgs is showing null .
];`
angular typescript
1个回答
0
投票

这样做。

bgs= [];
public lineChartData: Array<any>

ngOnInit(){
    this.lineChartData = []
    . . .
}

getbgs() {
    this.bgsService.getbgss(this.token).subscribe(
        data => {
            this.bgs = data.map(k => k.bgs);    
            this.lineChartData = [
                { data: [this.bgs], label: 'Series A' }
            ]
        }
   );
}
© www.soinside.com 2019 - 2024. All rights reserved.