I am using angular2-highcharts but I don't think this issue is specific to it.
The issue I am having is that the chart is rendered with an empty array before it is updated with the new data. I eventually want to use a click event to have testArray updated with the API call and launch a dialog-box containing a chart component showing that data. So I need it all to happen synchronously somehow or use an observable to wait for the data?
Template:
<chart type="StockChart" [options]="options"></chart>
Typescript:
testArray = []
options: Object;
httpCall():Observable<any>{
return this._http.get(httpUrl, options)
.map((res:Response)=> res.json()
)};
updateArray(){
this.httpCall()
.subscribe(res =>{
for (let data of res.data){
this.testArray.push([
Date.parse(data['date']),
parseInt(data['value'])
])
}
})
};
// This is for chart:
makeGraph(){
this.options = {
series: [{
type: 'column',
data: this.testArray,
}]
}
}
Any help would be great