mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复 ECharts 数据加载太快时渲染报错问题 (#3950)
* fix: 修复 ECharts 数据加载太快时渲染报错问题 * 补上 cancel
This commit is contained in:
parent
c6b10613a8
commit
6bb113e642
@ -30,6 +30,7 @@ import {
|
||||
} from '../Schema';
|
||||
import {ActionSchema} from './Action';
|
||||
import {isAlive} from 'mobx-state-tree';
|
||||
import debounce from 'lodash/debounce';
|
||||
|
||||
/**
|
||||
* Chart 图表渲染器。
|
||||
@ -180,6 +181,7 @@ export class Chart extends React.Component<ChartProps> {
|
||||
|
||||
this.refFn = this.refFn.bind(this);
|
||||
this.reload = this.reload.bind(this);
|
||||
this.reloadEcharts = debounce(this.reloadEcharts.bind(this), 300); //过于频繁更新 ECharts 会报错
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
this.mounted = true;
|
||||
|
||||
@ -225,6 +227,7 @@ export class Chart extends React.Component<ChartProps> {
|
||||
|
||||
componentWillUnmount() {
|
||||
this.mounted = false;
|
||||
(this.reloadEcharts as any).cancel();
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
|
||||
@ -435,14 +438,17 @@ export class Chart extends React.Component<ChartProps> {
|
||||
} else {
|
||||
this.echarts?.hideLoading();
|
||||
}
|
||||
|
||||
this.echarts?.setOption(config!, this.props.replaceChartOption);
|
||||
this.reloadEcharts(config);
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reloadEcharts(config: any) {
|
||||
this.echarts?.setOption(config!, this.props.replaceChartOption);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
className,
|
||||
|
Loading…
Reference in New Issue
Block a user