From 4438b4cebe909e556516d6fbda3b4b0123a50dc8 Mon Sep 17 00:00:00 2001 From: lideming Date: Sat, 25 Nov 2023 14:50:41 +0800 Subject: [PATCH] fix(frontend): echarts resize --- neetbox/frontend/src/components/echarts.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/neetbox/frontend/src/components/echarts.tsx b/neetbox/frontend/src/components/echarts.tsx index 7adf1fb..9a6707a 100644 --- a/neetbox/frontend/src/components/echarts.tsx +++ b/neetbox/frontend/src/components/echarts.tsx @@ -2,9 +2,9 @@ import { useRef, useEffect, HTMLAttributes } from "react"; import * as echarts from "echarts"; export interface EChartsProps { - initialOption: () => echarts.EChartsOption; - updatingOption: echarts.EChartsOption; - style?: HTMLAttributes['style']; + initialOption: () => echarts.EChartsOption; + updatingOption: echarts.EChartsOption; + style?: HTMLAttributes["style"]; } export const ECharts = (props: EChartsProps) => { @@ -17,7 +17,13 @@ export const ECharts = (props: EChartsProps) => { chart.setOption(props.initialOption()); chartRef.current = chart; + const handleResize = () => { + chart.resize(); + }; + window.addEventListener("resize", handleResize); + return () => { + window.removeEventListener("resize", handleResize); chart.dispose(); }; }, []);