import { Component, OnInit } from "@angular/core"; import { HighlightResult } from "ngx-highlightjs"; import { NzMessageService } from "ng-zorro-antd/message"; import { addMilliseconds, format } from "date-fns"; @Component({ selector: "app-big-data-line-chart", templateUrl: "./big-data-line-chart.component.html", styleUrls: ["./big-data-line-chart.component.scss"], }) export class BigDataLineChartComponent implements OnInit { constructor(private message: NzMessageService) {} response: HighlightResult; typeScriptCode = `import { Component, OnInit } from "@angular/core"; import { addMilliseconds, format } from "date-fns"; @Component({ selector: "line-chart-demo", templateUrl: '' }) export class LineChartDemoComponent implements OnInit { constructor() {} chartDatas: any = { datas: [this.makeData(3000, 50), this.makeData(3000, 54)], seriesNames: ["Leq", "Lmax"], }; timer; ngOnInit() { this.timer = window.setInterval(() => { let level1 = 50 + Math.random(); let level2 = 51 + Math.random(); this.chartDatas = { datas: [this.makeData(3000, level1), this.makeData(3000, level2)], seriesNames: ["l10", "l50"], }; }, 3000); } 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; } } `; importModulStr = `import { ChartModule } from 'bcac-lib/business-component/chart';`; chartDatas: any = { datas: [this.makeData(3000, 57), this.makeData(3000, 60.1)], seriesNames: ["Leq", "Lmax"], }; timer; ngOnInit() { // this.timer = window.setInterval(() => { // let level1 = 50 + Math.random()*0.5; // let level2 = 51 + Math.random()*0.5; // this.chartDatas = { // datas: [this.makeData(3000, level1), this.makeData(3000, level2)], // seriesNames: ["l10", "l50"], // }; // console.log("chartDatas", this.chartDatas); // }, 2000); } copied($event) { if ($event.isSuccess) { this.message.success("复制成功"); } } 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; } }