先安装插件 

npm install echarts --save

代码

import React, { Component } from 'react';
// 引入 ECharts 主模块
import echarts from 'echarts/lib/echarts';
// 引入饼状图
import  'echarts/lib/chart/pie';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
// 引入图例组件
import 'echarts/lib/component/legend';

class Pie extends Component {
    constructor(props){
        super(props);

        this.state = {
            data1:8,
            data2:12
        }
    }
    componentDidMount(){
        let myChart = echarts.init(document.getElementById('pie'));
        // 绘制图表
        myChart.setOption({
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b}: {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'right',
                top: 'middle',
                data:['已签到','未签到']
            },
            series: [
                {
                    name:'考勤统计',
                    type:'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        normal: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                fontSize: '30',
                                fontWeight: 'bold'
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data:[
                        {
                            value: this.state.data1,
                            name:'已签到',
                            itemStyle: {
                                normal: {
                                    color: '#3AA0FF'
                                }
                            }},
                        {
                            value: this.state.data2,
                            name:'未签到',
                            itemStyle: {
                                normal: {
                                    color: '#E56363'
                                }
                            }
                        }
                    ]
                }
            ]
        });
    };
    render() {
        return (
            <div>
                <div id="pie" style={{width: '450px', height:'400px'} }></div>
            </div>
        )
    }
}
export default Pie;

 截图

React学习系列七Echarts pie

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2021-12-29
  • 2021-06-14
  • 2022-01-13
  • 2021-09-02
  • 2022-01-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
相关资源
相似解决方案