Add stacked bars for x types of flight
This commit is contained in:
@@ -142,13 +142,10 @@ export class ListOfTunnelFlightsComponent implements OnInit {
|
||||
this.serviceTunnelFlight.getTunnelFlightsByMonth(beginDate, endDate)
|
||||
.subscribe((data) => {
|
||||
const allMonths = this.getMontsBetweenDates(beginDate, endDate)
|
||||
const cumulatedTime = this.getCumulatedTimeByMonth(data, allMonths);
|
||||
const cumulatedTime = this.getCumulatedTimeByTypeByMonth(data, allMonths);
|
||||
this.barChartData = {
|
||||
labels: allMonths,
|
||||
datasets: [
|
||||
{ data: cumulatedTime, label: 'Time in tunnel' },
|
||||
{ data: cumulatedTime, label: 'Time in tunnel 2' }
|
||||
]
|
||||
datasets: cumulatedTime
|
||||
};
|
||||
|
||||
this.isLoading = false;
|
||||
@@ -168,50 +165,30 @@ export class ListOfTunnelFlightsComponent implements OnInit {
|
||||
return results;
|
||||
}
|
||||
|
||||
private getCumulatedTimeByMonth(stats: TunnelFlightByMonth[], allMonths: string[]): Array<number> {
|
||||
// type GraphModel = {
|
||||
// data: number[];
|
||||
// label: string;
|
||||
// }
|
||||
private getCumulatedTimeByTypeByMonth(stats: TunnelFlightByMonth[], allMonths: string[]): Array<any> {
|
||||
let tmpResults = new Map<string, number[]>();
|
||||
|
||||
// let results: Array<number> = [];
|
||||
|
||||
// for (let i = 0; i < allMonths.length; i++) {
|
||||
// const month = allMonths[i];
|
||||
// let tmp = stats.filter((d) => d.month == month);
|
||||
|
||||
// let sum: number = 0;
|
||||
// if (tmp.length > 0){
|
||||
// tmp.forEach(a => sum += a.nb);
|
||||
// }
|
||||
|
||||
// results.push(sum);
|
||||
// }
|
||||
|
||||
// return results;
|
||||
|
||||
let arr3 = Array.from({length: allMonths.length + 1}, (v, k) => 0);
|
||||
let disctintType = stats.map(item => item.type).filter((value, index, self) => self.indexOf(value) === index);
|
||||
let disctintType2 = Array.from(new Set(stats.map((item) => item.type)))
|
||||
|
||||
let results = new Map<string, number[]>();
|
||||
const disctintType = Array.from(new Set(stats.map((item) => item.type)));
|
||||
disctintType.forEach(type => {
|
||||
tmpResults.set(type, Array.from({length: allMonths.length}, (v, k) => 0));
|
||||
});
|
||||
|
||||
for (let i = 0; i < allMonths.length; i++) {
|
||||
const month = allMonths[i];
|
||||
let tmp = stats.filter((d) => d.month == month);
|
||||
let filteredStats = stats.filter((d) => d.month == month);
|
||||
|
||||
if (tmp.length > 0){
|
||||
tmp.forEach(a => {
|
||||
if (!results.has(a.type)) {
|
||||
results.set(a.type, [a.nb])
|
||||
} else {
|
||||
results[a.type].push(a.nb);
|
||||
}
|
||||
if (filteredStats.length > 0){
|
||||
filteredStats.forEach(fs => {
|
||||
tmpResults.get(fs.type)[i] += fs.nb;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new Array<number>();
|
||||
const results = Array.from(tmpResults, function (item) {
|
||||
return { label: item[0], data: item[1] }
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private footer = (tooltipItems) => {
|
||||
|
||||
Reference in New Issue
Block a user