From e5146fb2b0230b9a3c4002290639d69a4bc82467 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 16 十月 2024 11:41:32 +0800 Subject: [PATCH] 曲线查询改造 --- src/components/chat/chatComponents/hooks/useDrawChatChart.ts | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/chat/chatComponents/hooks/useDrawChatChart.ts b/src/components/chat/chatComponents/hooks/useDrawChatChart.ts index 5266c73..2f057e5 100644 --- a/src/components/chat/chatComponents/hooks/useDrawChatChart.ts +++ b/src/components/chat/chatComponents/hooks/useDrawChatChart.ts @@ -16,28 +16,38 @@ resizeChart?.(width, height); }; - onMounted(() => { + const initChart = () => { setTimeout(() => { - const parent = chartRef.value.parentElement; + const instance = echarts.getInstanceByDom(chartRef.value); + if (!instance) { + const parent = chartRef.value.parentElement; + const parentBound = parent.getBoundingClientRect(); - const parentBound = parent.getBoundingClientRect(); - chartInstance.value = echarts.init(chartRef.value, undefined, { - width: parentBound.width, - height: parentBound.height, - }); - resizeChart = debounce((width, height) => { - chartInstance.value.resize({ - width: width, - height: height, + chartInstance.value = echarts.init(chartRef.value, undefined, { + width: parentBound.width, + height: parentBound.height, + locale: 'ZH', }); - }); + + resizeChart = debounce((width, height) => { + chartInstance.value.resize({ + width: width, + height: height, + }); + }); + } drawChart(); - }, 300); + }, 100); + }; + + onMounted(() => { + initChart(); }); return { chartContainerResize, chartInstance, + }; }; -- Gitblit v1.9.3