Echarts3实例 环形多标注图

前言

    在实现环形图的时候,label属性只能设置在内部和外部,不能实现同时存在的,这时,需要同Echarts的graphic属性作为label标签进行替代和填充。

实现效果

在这里插入图片描述

实现代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html,body{
            height: 100%;
        }
        *{
            margin: 0px;
            height: 0px;
        }
        #chartDiv{
            width: 520px;
            height: 300px;
            border: 1px solid red;
        }
    </style>
    <script src="js/echarts.min.js"></script>
</head>
<body>
<div id="chartDiv"></div>

<script>
    var chartDiv = echarts.init(document.getElementById("chartDiv"));

    var option = {
        title:{
            text:"多标注环形图"
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        color:['#7BBCFE','#F7D272','#F9738D'],
        grid: {
            containLabel:true
        },
        graphic:[{
            type:'text',
            left:'center',
            top:'40%',
            style:{
                text:'访问总量',
                fill:'#000',
                width:30,
                height:30,
                fontSize:24,
            }
        },{
            type:'text',
            left:'center',
            top:'50%',
            style:{
                text:'2000次',
                fill:"red",
                width:30,
                height:30,
                fontSize:14,
            }
        }],
        series: [
            {
                name:'',
                type:'pie',
                radius: ['50%', '60%'],
                center: ['50%','50%'],
                //avoidLabelOverlap: true,
                label: {
                    normal: {
                        formatter: '{a|{b}}{abg|}\n{hr|}\n  {b|数量:}{c}  {per|{d}%}  ',//空格也起作用
                        backgroundColor: '#eee',
                        borderColor: '#aaa',
                        borderWidth: 1,
                        borderRadius: 2,
                        rich: {
                            a: {
                                color: '#999',
                                lineHeight: 20,
                                align: 'center'
                            },
                            hr: {
                                borderColor: '#aaa',
                                width: '100%',
                                borderWidth: 0.5,
                                height: 0
                            },
                            b: {
                                fontSize: 12,
                                lineHeight: 20
                            },
                            per: {
                                color: '#eee',
                                backgroundColor: '#334455',
                                padding: [2, 4],
                                borderRadius: 2
                            }
                        }
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '14',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: true,
                    }
                },
                data:[
                    {value:335, name:'直达'},
                    {value:679, name:'营销广告'},
                    {value:1548, name:'搜索引擎'}
                ]
            }
        ]
    };
    chartDiv.setOption(option);
</script>
</body>
</html>
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值