
$vars: (3) ['seriesName', 'name', 'value']
borderColor: "#444"
color: "rgba(146,211,226,1)"
componentIndex: 0
componentSubType: "map"
componentType: "series"
data: {name: 'Islands', value: 3157}
dataIndex: 1
dataType: undefined
dimensionNames: []
encode: {value: Array(1)}
event: {type: 'click', event: PointerEvent, target: TSpan, topTarget: TSpan, cancelBubble: false, …}
name: "Islands"
seriesId: "\u0000series\u00000\u00000"
seriesIndex: 0
seriesName: "series\u00000"
seriesType: "map"
type: "click"
value: 3157

import * as echarts from 'echarts';
import { useEffect, useRef } from 'react';
import './index.less';
import mapData from '../../pages/test/hongkong.json';
interface ECHARTINIT {
options: any;
type?: string;
otherSource?: any;
soureName?: string;
}
export default function EchartInit(props: ECHARTINIT) {
const { options, type, soureName = '', otherSource } = props;
const curRef = useRef(null);
let echart: any = null;
const initEchart = () => {
echart = echarts.init(curRef.current as unknown as HTMLElement);
if (type === 'map') {
echarts.registerMap(soureName, { geoJSON: mapData });
}
window.addEventListener('resize', handleResize);
options && echart.setOption(options);
}
const handleResize = () => {
try {
echart.resize();
} catch (err) { }
}
useEffect(() => {
initEchart();
return () => {
window.removeEventListener('resize', handleResize);
};
}, [options]);
useEffect(() => {
echart.on('click', (params: any) => {
console.log('params', params);
})
}, [])
return (
<div ref={curRef} className="echart"></div>
)
}
