ui: resize chart on window
This commit is contained in:
parent
05d5aadbd2
commit
e4e77b4cfd
3 changed files with 10 additions and 0 deletions
|
|
@ -22,6 +22,9 @@ function ORBarChart(props: BarChartProps) {
|
|||
React.useEffect(() => {
|
||||
if (!chartRef.current) return;
|
||||
const chart = echarts.init(chartRef.current);
|
||||
const obs = new ResizeObserver(() => chart.resize())
|
||||
obs.observe(chartRef.current);
|
||||
|
||||
const categories = buildCategories(props.data);
|
||||
const { datasets, series } = buildBarDatasetsAndSeries(props, props.horizontal ?? false);
|
||||
|
||||
|
|
@ -72,6 +75,7 @@ function ORBarChart(props: BarChartProps) {
|
|||
|
||||
return () => {
|
||||
chart.dispose();
|
||||
obs.disconnect();
|
||||
delete (window as any).__seriesValueMap[chartUuid.current];
|
||||
delete (window as any).__seriesColorMap[chartUuid.current];
|
||||
delete (window as any).__categoryMap[chartUuid.current];
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ function ORLineChart(props: Props) {
|
|||
React.useEffect(() => {
|
||||
if (!chartRef.current) return;
|
||||
const chart = echarts.init(chartRef.current);
|
||||
const obs = new ResizeObserver(() => chart.resize())
|
||||
obs.observe(chartRef.current);
|
||||
|
||||
const categories = buildCategories(props.data);
|
||||
const { datasets, series } = buildDatasetsAndSeries(props);
|
||||
|
|
@ -85,6 +87,7 @@ function ORLineChart(props: Props) {
|
|||
|
||||
return () => {
|
||||
chart.dispose();
|
||||
obs.disconnect();
|
||||
delete (window as any).__seriesValueMap[chartUuid.current];
|
||||
delete (window as any).__seriesColorMap[chartUuid.current];
|
||||
delete (window as any).__categoryMap[chartUuid.current];
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ function PieChart(props: PieChartProps) {
|
|||
};
|
||||
|
||||
chartInstance.setOption(option);
|
||||
const obs = new ResizeObserver(() => chartInstance.resize())
|
||||
obs.observe(chartRef.current);
|
||||
|
||||
chartInstance.on('click', function (params) {
|
||||
onClick([{ name: params.name, value: params.value }]);
|
||||
|
|
@ -108,6 +110,7 @@ function PieChart(props: PieChartProps) {
|
|||
|
||||
return () => {
|
||||
chartInstance.dispose();
|
||||
obs.disconnect();
|
||||
};
|
||||
}, [data, label, onClick, inGrid]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue