沈斌
2018-07-13 b54dbd54bc18ebea847b8c8697e06394df499006
src/app/routes/statistics/analysis/analysis.component.ts
@@ -13,7 +13,8 @@
})
export class AnalysisComponent implements OnInit, OnDestroy {
    data: any = {};
    offlineChartData1: any[] = [];
    offlineChartData2: any[] = [];
    constructor(
        private deviceService: DeviceService,
@@ -23,34 +24,24 @@
    }
    ngOnInit() {
        const searchData = [];
        for (let i = 0; i < 50; i += 1) {
            searchData.push({
                index: i + 1,
                point: `监测站点-${i}`,
                value: Math.floor(Math.random() * 100)
        const offlineChartData1 = [];
        const offlineChartData2 = [];
        for (let i = 0; i < 20; i += 1) {
            offlineChartData1.push({
                x: new Date().getTime() + 1000 * 60 * 30 * i,
                y1: Math.floor(Math.random() * 100) + 10,
                y2: Math.floor(Math.random() * 100) + 10
            });
            offlineChartData2.push({
                x: new Date().getTime() + 1000 * 60 * 30 * i,
                y1: Math.floor(Math.random() * 100) + 10,
                y2: Math.floor(Math.random() * 100) + 10
            });
        }
        this.data = {
            searchData: searchData
        };
        this.offlineChartData1 = offlineChartData1;
        this.offlineChartData2 = offlineChartData2;
    }
    ngOnDestroy(): void {
    }
    sort(sortName, sortValue) {
        this.data.searchData = [
            ...(<any[]>this.data.searchData).sort((a, b) => {
                if (a[sortName] > b[sortName]) {
                    return (sortValue === 'ascend') ? 1 : -1;
                } else if (a[sortName] < b[sortName]) {
                    return (sortValue === 'ascend') ? -1 : 1;
                } else {
                    return 0;
                }
            })
        ];
    }
}