I am currently working with Angular/Typescript and utilizing the amcharts library version 4, specifically focusing on the multi line graph feature. When constructing the chart data, I have noticed that it only functions correctly with a single push to the chart array.
Here is an example of my code:
chart.data = [];
let hvacData: any = '';
for (let i = 0; i < this.chartTradeData['HVAC'].length; i++) {
const newDate = new Date(this.chartTradeData['HVAC'][i]['calendarDate']);
hvacData = this.chartTradeData['HVAC'][i]['revWorkDay'];
hvacData = parseInt(hvacData);
chart.data.push({
date: newDate,
hvacData
});
}
let plumbingData: any = '';
for (let i = 0; i < this.chartTradeData['Plumbing'].length; i++) {
const newDate = new Date(this.chartTradeData['Plumbing'][i]['calendarDate']);
plumbingData = this.chartTradeData['Plumbing'][i]['revWorkDay'];
plumbingData = parseInt(plumbingData);
chart.data.push({
date: newDate,
plumbingData
});
}
let electricalData: any = '';
for (let i = 0; i < this.chartTradeData['Electrical'].length; i++) {
const newDate = new Date(this.chartTradeData['Electrical'][i]['calendarDate']);
electricalData = this.chartTradeData['Electrical'][i]['revWorkDay'];
electricalData = parseInt(electricalData);
chart.data.push({
date: newDate,
electricalData
});
}
The issue is that the method above only displays the first line on the graph. My goal is to find a way to perform all these pushes simultaneously, resulting in a combined output like this after the loops:
chart.data.push({
date: newDate,
hvacData,
plumbingData,
electricalData
});
}
The structure of the object I am iterating over is shown here: