From 9adc219110433853d9e7017e94502aa0a3819e7f Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Mon, 05 Mar 2018 10:36:10 +0800 Subject: [PATCH] 报表优化 --- src/app/routes/report/report.component.ts | 67 +++++++++++++++++---------------- 1 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/app/routes/report/report.component.ts b/src/app/routes/report/report.component.ts index c74c6b9..a021f06 100644 --- a/src/app/routes/report/report.component.ts +++ b/src/app/routes/report/report.component.ts @@ -4,29 +4,30 @@ import {HttpClient} from '@angular/common/http'; import {ActivatedRoute} from '@angular/router'; import * as echarts from 'echarts'; - +import * as $ from 'jquery'; @Component({ selector: 'app-report', templateUrl: './report.component.html', styles: [] }) export class ReportComponent implements OnInit { - - public data: any; - - public isShow = true; + [x: string]: any; constructor( - injector: Injector, + public injector: Injector, public http: HttpClient, public activeRoute: ActivatedRoute, public msgSrv: NzMessageService - ) { } + ) { + for (let index = 0; index < 19; index++) { + this.sensorArr.push(index); + } + } public echartOption = { title: { text: '', - subtext: '12������', + // subtext: '12������', left: 'center' }, tooltip: { @@ -37,7 +38,7 @@ left: 'left' }, toolbox: { - show: true, + show: false, feature: { dataZoom: { yAxisIndex: 'none' @@ -61,7 +62,7 @@ }, series: [ { - smooth: false, + smooth: true, type: 'line', data: [], name: '' @@ -80,10 +81,15 @@ ] }; + sensorArr: any = []; + arr = new Array(); + ngOnInit() { this.activeRoute.queryParams.subscribe(params => { const query = params; - this.http.get(environment.SERVER_BASH_URL + 'report/compare', {params: query}).subscribe((res: any) => { + console.info(query.label); + query.items = JSON.parse(query.items); + this.http.post(environment.SERVER_BASH_URL + 'report/compare', query).subscribe((res: any) => { if (res.code === 0) { this.msgSrv.error(res.message); } else { @@ -91,18 +97,34 @@ const data = res.data; if (data['time']) { option.xAxis.data = data['time']; - option.title.text = query.sensorName + query.label + '������������'; option.series[0].data = []; option.legend.data[0] = ''; option.series[0].name = ''; option.series[1].data = []; option.legend.data[1] = ''; option.series[1].name = ''; + option.xAxis.name = query.xAxisName; if (data.dataA) { const legendNamea = (query.deviceaName ? query.deviceaName : query.monitorPointaName) + query.time + query.label; - option.series[0].data = data.dataA; option.legend.data[0] = legendNamea; option.series[0].name = legendNamea; + let index = 0; + for (const key in data.dataA[0]) { + this.arr.push(index); + let split = key.split('-'); + option.title.text = split[1] + query.label + '������������'; + option.series[0].data = data.dataA[0][key]; + option.yAxis.name = split[2]; + const myChart = echarts.init(document.getElementById('mydiv' + index)); + myChart.setOption(option, true); + window.onresize = myChart.resize; + index++; + } + this.sensorArr.forEach(i => { + if (this.arr.indexOf(i) == -1) { + $('#mydiv' + i).remove(); + } + }); } if (data.dataB) { const legendNameb = (query.devicebName ? query.devicebName : params.monitorPointbName) + query.timeb + query.label; @@ -110,29 +132,10 @@ option.legend.data[1] = legendNameb; option.series[1].name = legendNameb; } - option.yAxis.name = query.sensorUnit; - option.xAxis.name = query.xAxisName; - const myChart = echarts.init(document.getElementById('mydiv')); - myChart.setOption(option, true); - window.onresize = myChart.resize; } - this.isShow = true; } - }); }); - } - doPrint() { - this.isShow = false; - window.print(); - } - printBtnBoolean = true; - printComplete() { - this.printBtnBoolean = true; - } - beforePrint() { - this.printBtnBoolean = false; - } } -- Gitblit v1.8.0