Guys i have declared a array object as shown in below code
public data: Array<Object> = [] ;
But, the real problem i having is when i make a rest api call this empty array object gets some value. i had tried consolling it. But in console it shown
[] // empty array object
my rest api call and forEach loop code to create new object and it pushes into the already declared Array Object
public data: Array<Object>= [] ;
so, guys my rest api and forEach loop code goes here,
getChartDetails(examName): void {
this.resultService.getChartDetails(examName).subscribe(response => {
this.p = response.percentage;
this.myRes = response.sectionPercentage;
this.len = response.sections.length;
this.myRes.forEach(ele => {
var obj = { value: 0, label: '', percentage: 0, color: "", highlight: "" };
let dashboardColors = this._baConfig.get().colors.dashboard;
obj.value = ele.correctedAnswerCount;
obj.label = ele.sectionName;
obj.percentage = ele.percentage;
obj.color = dashboardColors.surfieGreen;
obj.highlight = colorHelper.shade(dashboardColors.surfieGreen, 15);
this.data.push(obj);
});
}) }
private _loadDoughnutCharts() {
console.log(this.data);// here i consoled it
let el = jQuery('.chart-area').get(0) as HTMLCanvasElement;
console.log(el);
new Chart(el.getContext('2d')).Doughnut(this.data, {
segmentShowStroke: false,
percentageInnerCutout: 64,
responsive: true
});
}
ngAfterViewInit() {
this.getChartDetails(this.examName);
if(this.showChart){
this._loadDoughnutCharts();
}
if(this.showChart == true){
this.deleteSession();
}
}
Actual result on console is shown in below image empty array object
Expected result on console should be like this
[Object,Object,Object,Object,Object,Object,Object,Object,Object]
Guys help me to find a way for this problem.
And one more thing response from rest api getting properly