我正在将 Angular/Typescript 与 amcharts 库(版本 4)一起使用,特别是多线图。在构建图表数据时,它似乎只在一次推送到图表数组时才能正常工作。
这是我的代码:
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
});
}
像上面那样做只会渲染图表上的第一行。我需要弄清楚如何一次完成所有这些推送,以便在循环之后看起来像这样:
chart.data.push({
date: newDate,
hvacData,
plumbingData,
electricalData
});
}
我正在迭代的对象如下所示: