xufenglei
2018-07-24 13e21b46aa0a340737b918a65b381641dcf0b396
统计分析  对比图效果
2 files modified
90 ■■■■■ changed files
src/app/routes/statistics/analysis/analysis.component.html 6 ●●●●● patch | view | raw | blame | history
src/app/routes/statistics/analysis/analysis.component.ts 84 ●●●●● patch | view | raw | blame | history
src/app/routes/statistics/analysis/analysis.component.html
@@ -23,7 +23,8 @@
                同期对比
                <span class="text-md font-weight-normal" style="color:red">PM2.5</span>
            </ng-template>
            <timeline [data]="offlineChartData1" [height]="239" [padding]="[0, 0, 0, 0]" [titleMap]="{ y1: '本月数据', y2: '上月同期' }"></timeline>
            <!-- <timeline [data]="offlineChartData1" [height]="239" [padding]="[0, 0, 0, 0]" [titleMap]="{ y1: '本月数据', y2: '上月同期' }"></timeline> -->
            <div id="PM25" style="height: 300px; width: 100%"></div>
        </nz-card>
    </div>
</div>
@@ -35,7 +36,8 @@
                同期对比
                <span class="text-md font-weight-normal" style="color:red">PM10</span>
            </ng-template>
            <timeline [data]="offlineChartData2" [height]="239" [padding]="[0, 0, 0, 0]" [titleMap]="{ y1: '本月数据', y2: '上月同期' }"></timeline>
            <div id="PM10" style="height: 300px; width: 100%"></div>
            <!-- <timeline [data]="offlineChartData2" [height]="239" [padding]="[0, 0, 0, 0]" [titleMap]="{ y1: '本月数据', y2: '上月同期' }"></timeline> -->
        </nz-card>
    </div>
</div>
src/app/routes/statistics/analysis/analysis.component.ts
@@ -5,6 +5,7 @@
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: 'statistics-analysis',
@@ -24,38 +25,69 @@
        private http2: HttpClient) {
    }
    public option = {
      title: {
        text: '',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
        axisPointer: {
          type: 'cross'
        }
      },
      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: '上月同期'
        }
      ]
    };
    ngOnInit() {
        const offlineChartData1 = [];
        const offlineChartData2 = [];
      const offlineChartData = [[], [], [], []];
        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
          offlineChartData[0].push(data.this_month_PM2_5);
          offlineChartData[1].push(data.last_month_PM2_5);
          offlineChartData[2].push(data.this_month_PM10);
          offlineChartData[3].push(data.last_month_PM2_5);
          this.option.xAxis.data.push(data.format_time);
            });
            offlineChartData2.push({
              x: data.time,
              y1: data.this_month_PM10,
              y2: data.last_month_PM10
        const PM25 = echarts.init(document.getElementById('PM25'));
        this.option.series[0].data = offlineChartData[0];
        this.option.series[1].data = offlineChartData[1];
        PM25.setOption(this.option, false);
        window.onresize = PM25.resize;
        const PM10 = echarts.init(document.getElementById('PM10'));
        this.option.series[0].data = offlineChartData[2];
        this.option.series[1].data = offlineChartData[3];
        PM10.setOption(this.option, false);
        window.onresize = PM10.resize;
            });
          });
        });
//        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 {