我正在使用 http 从服务器获取数据,在service.ts
:
getAllCursenValue():Observable<Cursen[]>{
let cursen$ = this.http
.get(this.baseUrl,{headers: this.getHeaders()})
.map(mapCursen);
return cursen$;
}
function mapCursen(response:Response):Cursen[]{
return response.json().map(toCursen);
}
function toCursen(r:any):Cursen{
let cursen = <Cursen>({
id_boitier:r.id_boitier,
id_phase:r.id_phase,
date:new Date(r.date),
power:r.power,
voltage:r.voltage,
current:r.current,
phase:r.phase,
thd:r.thd,
acc:r.acc,
flags:r.flags,
added_info:r.added_info
});
return cursen;
}
在我的组件中,我想使用 highchart 显示这些数据,问题是当我单击按钮时图表中没有显示任何内容,我认为当我单击时数据还没有准备好
组件.ts:
getCursenByDateTest(){
this.cursenService
.getCursenValueByDateTest("2016-7-30","2016-7-31")
.subscribe(p => {
this.cursens = p;
console.log(p)
console.log(this.cursens.length);
});
}
单击按钮时的方法:控制台在打印对象之前打印“GGGGG”和“PPPPP”:
ChartLine(){
this.getCursenByDateTest();
console.log("GGGGGGGGGGGGGG");
console.log("PPPPPPPPPPPPPPPPPP",this.finaldate1);
this.options1 = {
chart: {
type: 'area'
},
title: {
text: 'Area chart with negative values'
},
xAxis: {
categories: this.voltagesMax
},
credits: {
enabled: false
},
series: [{
name: 'John',
data: this.voltagesMax
}]
};
}
在将它们发送到图表之前,如何获取所有数据?