import { Component, OnInit } from "@angular/core"; import { fromEvent } from "rxjs"; import { debounceTime } from "rxjs/operators"; import { CommomService } from "src/app/core/services/commom.service"; import { addMilliseconds, format } from "date-fns"; import { ENgxPrintComponent } from 'e-ngx-print'; import { ViewChild } from "@angular/core"; 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-big-data-line-chart", templateUrl: "./sub-big-data-line-chart.component.html", styleUrls: ["./sub-big-data-line-chart.component.scss"], }) export class SubBigDataLineChartComponent 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 = "噪声秒级数据"; // echart配置项 initEchart(style) { //获取数据 let simulateData = [ this.makeData(3000, 51.8), this.makeData(3000, 53) ]; style.interval.right = "30"; // 参数传递 let params = { customGrid:style.interval, style: style, unit: "dB", xAxisName: "", yAxisName: "noise level(dB)", yNameGap: 30, datas: simulateData, seriesNames: ["Leq", "Lmax"] }; this.echartOption = this.chartOptionService.getOptionBigDataLineChart(params); console.log(this.echartOption) } 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); } // 模拟数据 private makeData(num, level) { let datas = []; let a, b let dateTime = new Date("2020-10-01 00:00:00"); for (let i = 0; i < num; i++) { if (i % 30 === 0) { a = 2 * Math.random(); } if (i % 30 === 0) { b = 2 * Math.random(); } dateTime = addMilliseconds(dateTime, 1000); datas.push([ format(dateTime, "yyyy-MM-dd HH:mm:ss"), (level + 2 * Math.sin(i / 50) + a + b + Math.random()).toFixed(2), ]); } return datas; } }