diff --git a/dist/production-dist/index.html b/dist/production-dist/index.html index 9f1f1623..69a7163a 100644 --- a/dist/production-dist/index.html +++ b/dist/production-dist/index.html @@ -5,7 +5,7 @@ ray template - + diff --git a/src/components/RayChart/index.tsx b/src/components/RayChart/index.tsx index 3a59236c..b7b31836 100644 --- a/src/components/RayChart/index.tsx +++ b/src/components/RayChart/index.tsx @@ -140,7 +140,8 @@ const RayChart = defineComponent({ const settingStore = useSetting() const { themeValue } = storeToRefs(settingStore) const rayChartRef = ref() // `echart` 容器实例 - const echartInstance = ref() // `echart` 实例 + const echartInstanceRef = ref() // `echart` 拷贝实例, 解决直接使用响应式实例带来的问题 + let echartInstance: EChartsInstance // `echart` 实例 const cssVarsRef = computed(() => { const cssVars = { @@ -215,9 +216,10 @@ const RayChart = defineComponent({ const element = rayChartRef.value as HTMLElement const options = useMergeOptions() - echartInstance.value = echarts.init(element, theme) + echartInstance = echarts.init(element, theme) + echartInstanceRef.value = echartInstance - options && echartInstance.value.setOption(options) + options && echartInstance.setOption(options) } const renderThemeChart = (bool?: boolean) => { @@ -237,15 +239,15 @@ const RayChart = defineComponent({ * 销毁 `chart` 实例, 释放资源 */ const destroyChart = () => { - if (echartInstance.value) { - echartInstance.value.clear() - echartInstance.value.dispose() + if (echartInstance) { + echartInstance.clear() + echartInstance.dispose() } } watch( - () => [themeValue.value, props.showAria], - ([theme]) => { + () => themeValue.value, + (theme) => { if (props.autoChangeTheme) { destroyChart() @@ -254,6 +256,15 @@ const RayChart = defineComponent({ }, ) + watch( + () => props.showAria, + () => { + destroyChart() + + renderThemeChart() + }, + ) + onBeforeMount(async () => { await registerChartCore() }) @@ -275,7 +286,7 @@ const RayChart = defineComponent({ return { rayChartRef, cssVarsRef, - echartInstance, + echartInstance: echartInstanceRef, } }, render() { diff --git a/src/views/echart/index.tsx b/src/views/echart/index.tsx index 4e641a8f..b08e4f57 100644 --- a/src/views/echart/index.tsx +++ b/src/views/echart/index.tsx @@ -11,7 +11,7 @@ const Echart = defineComponent({ const baseOptions = { legend: { - data: ['日期'], + // data: ['日期'], }, tooltip: {}, xAxis: {