import { Component, OnInit } from "@angular/core"; import { ViewChild } from "@angular/core"; import { fromEvent } from "rxjs"; import { debounceTime } from "rxjs/operators"; import { CommomService } from "src/app/core/services/commom.service"; import { ENgxPrintComponent } from 'e-ngx-print'; import { ChartOptionService } from 'src/app/core/services/chartServices/chart-option.service'; import { ChartMenuService } from 'src/app/core/services/chartServices/chart-menu.service'; @Component({ selector: 'app-sub-point-value-line-chart', templateUrl: './sub-point-value-line-chart.component.html', styleUrls: ['./sub-point-value-line-chart.component.scss'] }) export class SubPointValueLineChartComponent implements OnInit { @ViewChild('print1', {static: false}) print1Component: ENgxPrintComponent; constructor( private commomService: CommomService, private chartOptionService: ChartOptionService, private chartMenuService: ChartMenuService, ) {} ngOnInit() { this.initEchart(this.commomService.changeFontSize()); fromEvent(window, "resize") .pipe(debounceTime(200)) .subscribe(() => { let style = this.commomService.changeFontSize(); this.optionInit.setOption({ legend: { itemWidth: style.fontSize, itemHeight: style.fontSize, }, toolbox: { itemSize: style.toolboxSize, }, // grid: style.interval, }); }); } optionInit; onOptionInit(ec) { this.optionInit = ec; } echartOption; // 图名 chartName = "月平均气温"; initEchart(style) { //获取数据 //获取数据 let simulateData = this.makeData(); style.interval.right = "110"; // 参数传递 let params = { customGrid: style.interval, style: style, unit: "℃", xAxisName: "", yAxisName: "气温(℃)", xAxisDatas: simulateData.xAxisDatas, yNameGap: simulateData.yNameGap, seriesNames: simulateData.seriesNames, datas: simulateData.datas, }; this.echartOption = this.chartOptionService.getOptionPointValueLineChart(params); } closePanel(event) { event.fromElement.setAttribute('style','display:none') } downloadImage(imageType: string, fileName: string) { this.chartMenuService.downloadEchartImage(this.optionInit, fileName, imageType); } printComplete() { } customPrint() { this.chartMenuService.customPrint(this.optionInit, this.print1Component); } fullScreen(event) { this.chartMenuService.fullScreen(event.srcElement.parentNode.parentNode.parentNode.parentNode); } makeData() { let xAxisDatas = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']; let seriesNames = []; let datas =[]; for(let i=1; i<50; i++) { seriesNames.push('监测站点' + i); let subDatas = []; for(let j=0; j<12; j++) { subDatas.push((50 + 20*Math.random()).toFixed(2)); } datas.push(subDatas); } let dataObj = { xAxisDatas: xAxisDatas, seriesNames: seriesNames, yNameGap: 30, datas:datas }; return dataObj; } }