Echarts【参考】B02.饼状图

import * as echarts from 'echarts';

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option = {
    color: ['#4D9CFF', '#FF8286', '#F7B500', '#2DB596', '#A695FF'],
    title: {
        show: true,
        text: '{title|执行总数}\n{num|8}',
        left: 'center',
        top: 'center',
        textStyle: {
            rich: {
                title: {
                    fontSize: 21,
                    color: '#999',
                    lineHeight: 50,
                },
                num: {
                    fontSize: 40,
                    color: '#000',
                    lineHeight: 40,
                }
            }
        }
    },
    tooltip: {
        trigger: 'item',
        formatter: function(params) {
            let html = '<div style="margin-top: 5px;margin-right: 5px;float: left; border-radius: 10px;width: 10px;height:10px;background-color: ' + params.color + '"></div>'
            let _name = params.name.split('/')
            return html + _name[0] + ': ' + params.percent + '%'
        }
    },
    series: {
            type: 'pie',
            radius: [70, 100],
            left: 'center',
            label: {
                fontSize: 21,
                alignTo: 'edge',
                formatter: '{b}\n',
                edgeDistance: 10,
                lineHeight: 30,
                rich: {
                    title: {
                        fontSize: 21,
                        color: '#999',
                        lineHeight: 50,
                    },
                }
            },
            labelLayout: function (params) {
                var isLeft = params.labelRect.x < myChart.getWidth() / 2;
                var points = params.labelLinePoints;
                points[2][0] = isLeft
                    ? params.labelRect.x
                    : params.labelRect.x + params.labelRect.width;
                return {
                    labelLinePoints: points
                };
            },
            data: [
                { name: '类目1', value: 38, label: {color: '#4D9CFF'}},
                { name: '类目2', value: 23, label: {color: '#FF8286'}},
                { name: '类目3', value: 22, label: {color: '#F7B500'}},
                { name: '类目4', value: 13, label: {color: '#2DB596'}},
                { name: '类目5', value: 12, label: {color: '#A695FF'}},
            ]
        }
};

option && myChart.setOption(option);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琴 韵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值