/* //y轴显示数据 Data:{ name:string, data:string[], } props:{ xData:string[], //x轴时间数据 dataList:Data[], //数据列表 } */ import { useEffect, useRef, useState } from 'react'; import echarts from 'echarts'; import styles from './index.less'; import moment from 'moment'; import { Empty } from 'antd'; //图表模块 const BarChartModule = props => { const chartDomRef = useRef(); const chartRef = useRef(); const { xData, dataList } = props; useEffect(() => { chartRef.current = echarts.init(chartDomRef.current); window.addEventListener('resize', resetChart); return () => window.removeEventListener('resize', resetChart); }, []); useEffect(() => { if (!chartRef.current || !dataList) return; const option = { ...defaultOption }; option.xAxis.data = xData; option.series = dataList.map((item, idx) => { return { ...option.series[idx], ...item, }; }); chartRef.current.clear(); chartRef.current.setOption(option); chartRef.current.resize(); }, [xData, dataList]); const resetChart = () => { if (chartRef.current) chartRef.current.resize(); }; const getStyle = () => { if (dataList && dataList.length != 0) return { width: '100%', height: '100%' }; else return { width: '100%', height: '100%', display: 'none' }; }; return (