效果图:
封裝代码:
import React, {useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import * as echarts from 'echarts'
import 'echarts-gl'
/**
* 图
*/
interface BBIChartProps {
options: any;
style?: React.CSSProperties;
handleClick?: Function,
onLoad?: Function,
loading?: boolean;
}
const Chart = (props: BBIChartProps) => {
const domRef: any = React.useRef();
useEffect(() => {
const {current} = domRef;
if (current) {
let instance: any = echarts.getInstanceByDom(current) || echarts.init(current);
const resize = (): void => instance.resize();
window.removeEventListener('resize', resize);
window.addEventListener('resize', resize);
// 加载状态
function showLoading(instance: any): void {
instance.showLoading('default', {
text: '',
color: 'rgba(255, 255, 255, 0.3)',
textColor: '#000000',
maskColor: 'rgba(255, 255, 255, 0)',
zlevel: 0,
});
}
showLoading(instance);
instance.setOption(props.options);
instance.off("click");
instance.on("click", (event: any) => {
props.handleClick && props.handleClick(event);
})
}
},