My issue is with dynamically adding data to my bar chart dataset as it keeps returning undefined. Here's the current working version:
public barChartData: ChartDataSets[] = [
{ data: [], label: 'High' },
{ data: [], label: 'Medium' },
{ data: [], label: 'Low' }
];
this.barChartData[0].data.push(2);
console.log(this.barChartData[0].label);
console.log(this.barChartData[0].data);
The above code works, but it's not flexible enough because I don't know in advance how much data there will be. This led me to try a different approach:
public barChartData: ChartDataSets[] = [];
public barChartDataCount = 0;
for (let index = 0; index < this.tag.length; index++) {
if(this.tag[index].type=='type')
{
this.barChartData[this.barChartDataCount].label=this.tag[index].name;
this.barChartData[this.barChartDataCount].data.push(2);
this.barChartDataCount++;
this.numType++;
}
}
However, when attempting this method, I encountered an error: ERROR TypeError: Cannot set properties of undefined (setting 'label')