先下包
下完包之后可以根据自己的方式进行先修改再使用或者直接使用再修改
在react里面使用引入全局要加* as
引用
图表引入之后 用一个盒子进行ref绑定 需要对echarts进行初始化
最后
初始化完成之后就可以给mycharts赋值 把自己图表的数据估值给他 就可以出来一个自己想要的效果 数据里面的值也是可以在官网进行搜索改换
import './index.css'
import { useState, useEffect, useRef } from 'react';
import { getTq, getStudents } from '../../request/tq'
import * as echarts from 'echarts';
import dayjs from 'dayjs'
const Home = () => {
let [tq, setTq] = useState({});
const echartsBox = useRef(null)
const [option, setOption] = useState({
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine'],
icon: 'circle',
textStyle: {
color: '#fff'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
// type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210],
showSymbol: false,
smooth: true
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310],
showSymbol: false,
smooth: true
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410],
showSymbol: false,
smooth: true
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320],
showSymbol: false,
smooth: true
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320],
showSymbol: false,
smooth: true
}
]
});
useEffect(() => {
getTq({
unescape: 1,
version: "v91",
appid: "74128726",
appsecret: "uxa4ZzuT"
}).then(res => {
console.log(res);
setTq(res.data)
});
const mycharts = echarts.init(echartsBox.current);
getStudents().then(res => {
// console.log(res);
option.legend.data = res.data.data.result[0].legend.data
option.series = res.data.data.result[0].series.map(item=>{
return {
...item,
showSymbol:false,
smooth:true
}
});
setOption(option);
mycharts.setOption(option);
})
mycharts.setOption(option);
}, [option])
return (
<div className="box">
<header>
</header>
<main>
<div className='left'>
<div className='tq'>
<div className='title'>
环境监测
</div>
<div className='tqsj'>
{/* 将天气渲染到里面 */}
<div className='tq-top'>
<div className='tq-top-left'>
℃
</div>
<div className='tq-top-center'>
<div className='tq-top-center-top'>
</div>
<div className='tq-top-center-bot'>
1~2 <span className='iconfont icon-sheshidu01'></span>
</div>
</div>
<div className='tq-top-right'>
高温预警
</div>
</div>
<div className='tq-center'></div>
<div className='tq-bot'></div>
</div>
</div>
<div className='tq'>
<div className='title'>
环境监测
</div>
<div className='tqsj' ref={echartsBox}>
</div>
</div>
</div>
<div className='center'>
</div>
<div className='right'>
</div>
</main>
</div>
)
}
export default Home