Skip to content

Commit

Permalink
fix(frontend): echarts resize
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming committed Nov 25, 2023
1 parent ab8368e commit 4438b4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions neetbox/frontend/src/components/echarts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>['style'];
initialOption: () => echarts.EChartsOption;
updatingOption: echarts.EChartsOption;
style?: HTMLAttributes<HTMLElement>["style"];
}

export const ECharts = (props: EChartsProps) => {
Expand All @@ -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();
};
}, []);
Expand Down

0 comments on commit 4438b4c

Please sign in to comment.