fengxiang
2018-08-02 c69ddde7828d777f04c6468c269aaa0aa03d72c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { environment } from '@env/environment';
import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
import { HttpClient } from '@angular/common/http';
import * as moment from 'moment';
import { DeviceService } from '@business/services/http/device.service';
import * as echarts from 'echarts';
import * as $ from 'jquery';
 
@Component({
    selector: 'environment-management',
    templateUrl: './management.component.html',
    styleUrls: ['./management.component.less'],
    providers: [DeviceService]
})
export class EnvironmentManagementComponent implements OnInit, OnDestroy {
 
    constructor(
        private deviceService: DeviceService,
        private http: _HttpClient,
        public msg: NzMessageService,
        private http2: HttpClient) {
    }
  
    public option = {
      tooltip: {
        trigger: 'item',
        axisPointer: {
          type: 'cross'
        }
      },
      legend: {
        right: '10%',
        top: '10%',
        data: ['本月数据', '上月同期']
      },
      xAxis: {
        type: 'category'
      },
      yAxis: {
        type: 'value',
        name: '单位:ug/m³'
      },
      series: [
        {
          type: 'line',
          smooth: true,
          name: '本月数据'
        }, {
          type: 'line',
          smooth: true,
          name: '上月同期'
        }
      ]
    };
  
    ngAfterViewInit() {
      const PM25 = echarts.init(document.getElementById('PM25'));
      PM25.showLoading();
      const params = {
        type: 'month',
        sensors: JSON.stringify(['e1']),
        items: JSON.stringify([
          {areaCode: 320583, formatTime: moment().format('YYYY-MM')},
          {areaCode: 320583, formatTime: moment().subtract(1, 'M').format('YYYY-MM')}
        ])
      };
      this.http2.get(environment.SERVER_BASH_URL + 'report/compare', {params: params}).subscribe((res: any) => {
        const PM25Option = $.extend(true,
          {
            xAxis: {data: res.data.times},
            series: [
              {data: res.data.datas[0]['e1']},
              {data: res.data.datas[1]['e1']}
            ]
          },
          this.option);
        PM25.setOption(PM25Option, false);
        window.onresize = PM25.resize;
        PM25.hideLoading();
      });
    }
    
    ngOnInit() {
    }
 
    ngOnDestroy(): void {
    }
}