fix bug
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
import { Component, ElementRef, Input, NgZone, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
|
||||
import { G2MiniAreaClickItem } from '@delon/chart/mini-area';
|
||||
import DataSet from '@antv/data-set';
|
||||
import { Chart } from '@antv/g2';
|
||||
import { DataService } from 'src/app/routes/datatable/services/data.service';
|
||||
@Component({
|
||||
@ -9,43 +7,44 @@ import { DataService } from 'src/app/routes/datatable/services/data.service';
|
||||
styleUrls: ['./curve.component.less']
|
||||
})
|
||||
export class BusitableCurveComponent implements OnInit, OnChanges {
|
||||
@Input() chartData: any;
|
||||
el: any;
|
||||
@Input() chartData: any;
|
||||
chart: any;
|
||||
constructor(private service: DataService, private ngZone: NgZone) {
|
||||
|
||||
}
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (this.chartData) {
|
||||
// setTimeout(()=>{
|
||||
// this.chart.render(true)
|
||||
// }, 1000)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (this.chartData) {
|
||||
setTimeout(() => {
|
||||
this.ngZone.runOutsideAngular(() => this.init(this.el));
|
||||
}, 2000)
|
||||
|
||||
}
|
||||
reRender() {
|
||||
setTimeout(() => {
|
||||
this.chart.data(this.chartData);
|
||||
this.chart.render();
|
||||
}, 500)
|
||||
}
|
||||
|
||||
|
||||
handleClick(data: G2MiniAreaClickItem): void {
|
||||
this.service.msgSrv.info(`${data.item.x} - ${data.item.y}`);
|
||||
}
|
||||
|
||||
render(el: ElementRef<HTMLDivElement>): void {
|
||||
this.el = el.nativeElement
|
||||
// this.ngZone.runOutsideAngular(() => this.init(this.el));
|
||||
this.ngZone.runOutsideAngular(() => this.init(this.el));
|
||||
}
|
||||
|
||||
private init(el: HTMLElement): void {
|
||||
const chart = new Chart({
|
||||
this.chart = new Chart({
|
||||
container: el,
|
||||
autoFit: true,
|
||||
height: 500,
|
||||
});
|
||||
|
||||
chart.data(this.chartData);
|
||||
chart.scale({
|
||||
this.chart.data(this.chartData);
|
||||
this.chart.scale({
|
||||
year: {
|
||||
range: [0, 1],
|
||||
},
|
||||
@ -55,15 +54,15 @@ export class BusitableCurveComponent implements OnInit, OnChanges {
|
||||
},
|
||||
});
|
||||
|
||||
chart.tooltip({
|
||||
this.chart.tooltip({
|
||||
showCrosshairs: true, // 展示 Tooltip 辅助线
|
||||
shared: true,
|
||||
});
|
||||
|
||||
chart.line().position('time*value').label('value');
|
||||
chart.point().position('time*value');
|
||||
this.chart.line().position('time*value').label('value');
|
||||
this.chart.point().position('time*value');
|
||||
|
||||
chart.render();
|
||||
this.chart.render();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user