first commit
This commit is contained in:
31
frontend/src/components/common/EChart.tsx
Normal file
31
frontend/src/components/common/EChart.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import * as echarts from "echarts";
|
||||
import type { EChartsOption } from "echarts";
|
||||
|
||||
interface EChartProps {
|
||||
option: EChartsOption;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function EChart({ option, className = "h-80 w-full" }: EChartProps) {
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const chart = echarts.init(ref.current);
|
||||
chart.setOption(option);
|
||||
|
||||
const observer = new ResizeObserver(() => chart.resize());
|
||||
observer.observe(ref.current);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
chart.dispose();
|
||||
};
|
||||
}, [option]);
|
||||
|
||||
return <div ref={ref} className={className} />;
|
||||
}
|
||||
Reference in New Issue
Block a user