echarts实现环形图

前端框架使用的angular,使用echarts实现环形图

1. item.component.html

<div id="box1" class="pie"></div>
<div id="box2" class="pie"></div>

2. item.component.css

.pie {
    width:160px;
    height:160px;
    margin: 0 auto;
}

3. item.component.ts

ngAfterViewInit() {
      this.pie(11, '合格率', '#box1', ['#E91E63', '#F48FB1']);
      this.pie(54, '正确率', '#box2', ['#2196F3', '#BBDEFB']);

  }
pie(pieData: any, pieName: string, box: string, colors: string[] ): void {
    const that = this;
    const myChart = echarts.init(that.element.nativeElement.querySelector(box));
    const data = pieData;
    const name = pieName;
    const option = {
        grid: {
            top: 5,
            bottom: 5,
        },
        color: colors,
        series: [{
            name: 'valueOfMarket',
            type: 'pie',
            center: ['50%', '50%'], // 饼图的圆心坐标
            radius: ['60%', '70%'],
            avoidLabelOverlap: false,
            hoverAnimation: false,
            label: { //  饼图图形上的文本标签
                normal: { // normal 是图形在默认状态下的样式
                    show: true,
                    position: 'center',
                    color: '#000000',
                    fontSize: 14,
                    fontWeight: 'bold',
                    formatter: '{b}\n{c}%' // {b}:数据名; {c}:数据值; {d}:百分比
                }
            },
            data: [
                {
                    value: data,
                    name: name,
                    label: {
                        normal: {
                            show: true
                        }
                    }
                },
                {
                    value: 100 - data,
                    name: '',
                    label: {
                        normal: {
                        show: false
                        }
                    }
                }
            ]
        }]
    }
    myChart.setOption(option);
}

实现效果如图:

转载于:https://www.cnblogs.com/zeroingToOne/p/9220325.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值