Currently my method is this. I have a service that is subscribing to getting the data from my API.
Code: Select all
export class ReportService {
private reportUrl: string = environment.reportUrl;
constructor(private http: Http) {}
/**
* Get all SRs
*/
getSR(groupBy: string, beginDate:string, endDate:string): Observable<Report[]> {
return this.http.get(`${this.reportUrl}/SR?group_by="${groupBy}"&begin_date="${beginDate}"&end_date="${endDate}"`)
.map(res => res.json().data)
.catch(this.handleError);
}
Code: Select all
ngOnInit(){
.
.
.
let newData = [];
let dataSet1= [];
let labels = [];
this.reportService.getSR('Month', lastMonth, today)
.subscribe(data => {
dataSet1.push(data.map(a => a.sr_count))
let monthName = data.map(item => {
return item.month_name
})
labels.push.apply(labels, monthName)
console.log(labels) //["October", "September"]
});
console.log(labels) // I think its [["October", "September"]]
console.log(newData) // [[109,34]]
this.data = {
labels: labels, //undefined
datasets: [
{
label: 'First Dataset',
data: dataSet1, //undefined
fill: false,
borderColor: '#4bc0c0'
}
]
}
}
}
In my console you can see the first two arrays are outside the observable, the bottom array is inside the observable.
If anyone has any suggestions or can point me to a tutorial you'll be my hero!!