1π
β
The problem here is you use an async
method getTecajRazdoblje()
. But youβre trying to fill the array sync
way. So you need to correct that. Try this:
this.hnbProvider.getTecajRazdoblje(datum_poc, datum_kraj).subscribe(tecaj =>
{
this.tecaj = tecaj;
var i = 0;
for (var key in this.tecaj) {
if (this.tecaj[key].valuta == this.o_valuta){
this.array[i] = this.tecaj[key].srednji_tecaj;
i++;
}
this.lineChart = new Chart(this.lineCanvas.nativeElement,
{
type: 'line',
data: {
labels: this.lista_valuta,
datasets: [
{
label: "My First dataset",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data:this.array,
spanGaps: false,
}
]
}
});
}
});
}
Source:stackexchange.com