Level 58
You can use a for loop to iterate through the label array and push each item's name into the allCurrency array. Then, you can use the allCurrency array to set the label property of the datasets object in the data variable.
async function outlayGraph(label) {
const context = document.getElementById('outlayGraph').getContext('2d');
let data = 0;
let configuration = 0;
let allCurrency = [];
for(i in label) {
const item = label[i];
allCurrency.push(item.name);
}
data = {
labels: created_date,
datasets: [{
label: allCurrency[i],
borderColor: 'rgb(255, 0, 0)',
data: albanianLek
}]
};
configuration = {
type: 'line',
data,
options: {
tooltips: {
mode: 'index'
}
}
};
if (charts) {
charts.data.labels = created_date;
charts.data.datasets[0].data = albanianLek;
charts.data.datasets[1].data = britishPound;
charts.data.datasets[2].data = americanDollar;
charts.data.datasets[3].data = euro;
charts.update();
} else {
charts = new Chart(context, configuration);
}
}