React函数式组件中Echarts的应用
import React, { useEffect, useRef } from 'react';
import * as echarts from 'echarts';
export default function NewEcharts(){
const charfRef: any = useRef();
const options = {
title: { text: "ECharts", },
tooltip: {},
legend: {
data: ["销量", '销量1'],
},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
},
yAxis: {},
series: [
{
name: "销量",
type: "bar",
data: [5, 20, 36, 10, 10, 20],
},
{
name: "销量1",
type: 'line',
data: [5, 20, 36, 10, 10, 20],
},
],
};
useEffect(() => {
const chart = echarts.init(charfRef.current);
chart.setOption(options);
return () => {
chart.dispose()
}
}, [])
return <div ref={charfRef} style={{ width: 600, height: 400, margin: 100 }}></div>
}