xufenglei
2018-07-24 fd35962de838e033a8964e0959c99572f02b15f0
src/app/routes/statistics/analysis/analysis.component.ts
@@ -1,3 +1,4 @@
import { environment } from '../../../../environments/environment';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
@@ -13,7 +14,8 @@
})
export class AnalysisComponent implements OnInit, OnDestroy {
    data: any = {};
    offlineChartData1: any[] = [];
    offlineChartData2: any[] = [];
    constructor(
        private deviceService: DeviceService,
@@ -23,34 +25,39 @@
    }
    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 = [];
        const params = {size: '24'};
        this.http2.get(environment.SERVER_BASH_URL + 'demo/compare', {params: params}).subscribe((res: any) => {
          res.forEach(data => {
            offlineChartData1.push({
              x: data.time,
              y1: data.this_month_PM2_5,
              y2: data.last_month_PM2_5
            });
        }
        this.data = {
            searchData: searchData
        };
            offlineChartData2.push({
              x: data.time,
              y1: data.this_month_PM10,
              y2: data.last_month_PM10
            });
          });
        });
//        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.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;
                }
            })
        ];
    }
}