From 7aabdfc457bf7dd9a30f46b4d6efb032a196c3d8 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Wed, 25 Jul 2018 11:03:49 +0800
Subject: [PATCH] 环境管理 图表实现
---
src/app/routes/environment/management/management.component.ts | 90 ++++++++++++++++++++++++++++++--------------
1 files changed, 61 insertions(+), 29 deletions(-)
diff --git a/src/app/routes/environment/management/management.component.ts b/src/app/routes/environment/management/management.component.ts
index 68b73fe..ab2ee99 100644
--- a/src/app/routes/environment/management/management.component.ts
+++ b/src/app/routes/environment/management/management.component.ts
@@ -1,9 +1,11 @@
-import { Component, OnInit, OnDestroy } from '@angular/core';
+import { environment } from '../../../../environments/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';
@Component({
selector: 'environment-management',
@@ -13,7 +15,7 @@
})
export class EnvironmentManagementComponent implements OnInit, OnDestroy {
- data: any = {};
+ offlineChartData: any[] = [];
constructor(
private deviceService: DeviceService,
@@ -21,36 +23,66 @@
public msg: NzMessageService,
private http2: HttpClient) {
}
-
- ngOnInit() {
- const searchData = [];
- for (let i = 0; i < 50; i += 1) {
- searchData.push({
- index: i + 1,
- point: `������������-${i}`,
- value: Math.floor(Math.random() * 100)
- });
+
+ public option = {
+ tooltip: {
+ trigger: 'item',
+ axisPointer: {
+ type: 'cross'
}
-
- this.data = {
- searchData: searchData
- };
+ },
+ legend: {
+ right: '10%',
+ top: '10%',
+ data: ['������������', '������������']
+ },
+ xAxis: {
+ type: 'category',
+ data: []
+ },
+ yAxis: {
+ type: 'value',
+ name: '���������ug/m��'
+ },
+ series: [
+ {
+ data: [],
+ type: 'line',
+ smooth: true,
+ name: '������������'
+ }, {
+ data: [],
+ 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) => {
+ this.option.xAxis.data = res.data.times;
+ this.option.series[0].data = res.data.datas[0]['e1'];
+ this.option.series[1].data = res.data.datas[1]['e1'];
+ PM25.setOption(this.option, false);
+ window.onresize = PM25.resize;
+ PM25.hideLoading();
+ });
+ }
+
+ ngOnInit() {
}
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;
- }
- })
- ];
}
}
--
Gitblit v1.8.0