fix: fix renderEcharts refresh issue (#4741)
parent
6688a6b3c2
commit
d7d7466524
|
@ -31,12 +31,11 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
|
||||||
|
|
||||||
const getOptions = computed((): EChartsOption => {
|
const getOptions = computed((): EChartsOption => {
|
||||||
if (!isDark.value) {
|
if (!isDark.value) {
|
||||||
return cacheOptions;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
...cacheOptions,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,10 +51,14 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
|
||||||
|
|
||||||
const renderEcharts = (options: EChartsOption, clear = true) => {
|
const renderEcharts = (options: EChartsOption, clear = true) => {
|
||||||
cacheOptions = options;
|
cacheOptions = options;
|
||||||
|
const currentOptions = {
|
||||||
|
...options,
|
||||||
|
...getOptions.value,
|
||||||
|
};
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (chartRef.value?.offsetHeight === 0) {
|
if (chartRef.value?.offsetHeight === 0) {
|
||||||
useTimeoutFn(() => {
|
useTimeoutFn(() => {
|
||||||
renderEcharts(getOptions.value);
|
renderEcharts(currentOptions);
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}, 30);
|
}, 30);
|
||||||
return;
|
return;
|
||||||
|
@ -67,7 +70,7 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
}
|
}
|
||||||
clear && chartInstance?.clear();
|
clear && chartInstance?.clear();
|
||||||
chartInstance?.setOption(getOptions.value);
|
chartInstance?.setOption(currentOptions);
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}, 30);
|
}, 30);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue