先赞后看,养成习惯!
最近在写首页的数据图表,记录一下
npm install --save echarts
npm install --save echarts-for-react
要是卡的话,可以考虑cnpm
随便在官网找一个示例
我这里找了一个饼图,公司电脑有水印就不先截图了
option = {
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a}
{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
},
series: [
{
name: '访问来源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [
{
value: 335, name: '直接访问'},
{
value: 310, name: '邮件营销'},
{
value: 234, name: '联盟广告'},
{
value: 135, name: '视频广告'},
{
value: 1548, name: '搜索引擎'}
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
import React from 'react';
import {
Row,
Col,
} from 'antd';
import ReactEcharts from 'echarts-for-react';
import {
useDispatch, useSelector } from 'dva';
function homepage(props) {
const dispatch = useDispatch();
const loadingEffect = useSelector(state => state.loading);
const loading = loadingEffect.effects[...];
const businessMetrics_data = useSelector(state => state....data);
useEffect(()=>{
...
},[])
//直接复制到return后就行
let getOption = (sales,stores) =>{
return {
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a}
{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
},
series: [
{
name: '访问来源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [
{
value: 335, name: '直接访问'},
{
value: 310, name: '邮件营销'},
{
value: 234, name: '联盟广告'},
{
value: 135, name: '视频广告'},
{
value: 1548, name: '搜索引擎'}
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
}
return (
<div style={
{
marginTop:'10px'}}>
<Row gutter={
16}>
<Col span={
12}>
<Card>
<ReactEcharts option={
getOption()} />
</Card>
</Col>
<Col span={
12}>
<Card>
<ReactEcharts option={
getOption()} />
</Card>
</Col>
</Row>
</div>
);
}
export default homepage;
想放自己的数据和列名,将data换成自己写的变量就行,非常方便
新手小白,如果有帮助到你,能点个赞嘛!!谢谢!!!