I have a piece of code where I need to pass values from the 'dataList' array into this.data object's 'labels' and 'datasets'-> data.
When I try to directly set the values, I get an undefined result. So I created a variable to store values first and then attempt to pass it to labels and data.
My question is, how can I dynamically set values for labels and data from the dataList array?
this.dataList = [['label1', 200], ['label2', 300], ['label3', 500]];
// I want to access all labels to label, all numbers to data in below instead of using static data, I want to fetch data from the dataList array
this.data = {
labels: ['label1', label2, label3],
datasets: [
{
data: [200, 300, 500],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
};
Instead of hardcoding values in labels and data, I aim to populate them with dynamic data stored in the dataList array.