Echarts 环形图多层嵌套

Echarts 环形图多层嵌套如何实现?
本文主要分解展示环形图多层嵌套的一些option配置项,希望能帮到您!
如图:
在这里插入图片描述多层环形图本质就是多个饼图(圆),然后 分别给不同的饼图设置不同样式;具体实现要结合项目需求。

直接上代码:

option = {
  // 鼠标悬浮不显示数据提示框
        tooltip: {
            trigger: 'item',
            show:true,
            formatter: '{b} </br> 占比{d}%'
        },
        // 富文本显示中间文字
        title:{
            text: '{a|1000}\n{c|数量统计}',
            textStyle: {
                color: "#fff",
                fontWeight: '100',
                fontFamily:'PingFang',
                rich: {
                    a: {
                        fontSize: "30",
                        fontFamily:'PangMenZhengDao' ,
                        color: '#D8E9FF',
                        padding: [20,1,33,60]
                    },

                    c: {
                        fontSize: 20,
                        lineHeight: 35,
                        color: '#D8E9FF',
                        padding: [0,0,0,60]
                    }
                }
            },
            x: "20%",
            y: "center"
        },
        color: [
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#4A66C3 " },
                { offset: 1, color: "#5A80FA " }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#15A0E6" },
                { offset: 1, color: "#0B6ECE" }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#5BB1BC" },
                { offset: 1, color: "#358C9C" }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#8D98CC" },
                { offset: 1, color: "#616BA6" }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#EDE00E" },
                { offset: 1, color: "#D6BD06" }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#F6B14C" },
                { offset: 1, color: "#FC8A33" }
            ]),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#E87C5A" },
                { offset: 1, color: "#DA5E46" }
            ])
        ],
        // 图例位置
        legend: {
            top:'26%',
            right: '20%',
            orient : 'vertical',
            icon: "rect",
            itemHeight: 12,
            itemGap:30,
            textStyle: { //图例⽂字的样式
                color: '#BACEE3',
                fontSize: 14
            },
        },
        series: [
            {
                name: '占比',
                type: 'pie',
                radius: ['45%', '65%'],
                center:['30%','50%'],
                avoidLabelOverlap: true,
                emphasis: {
                    label: {
                        show: false,
                        fontSize: '20',
                        fontFamily:'PingFang',
                    }
                },
                label: {
                    color: '#D8E9FF',
                    fontFamily:'PingFang',
                    normal:{
                        show:false,
                        position:'center',
                        formatter: '{b} : {c}' , // 标签内容
                    },
                },
                labelLine: {
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 0)'
                    },
                    smooth: 0.2,
                    length: 10,
                    length2: 20
                },
                itemStyle: {
                    shadowBlur: 0,
                    shadowColor: 'rgba(255, 255, 255)'
                },
                data:[
                    { name: '苹果',value: 12},
                    { name: '香蕉',value: 13 },
                    { name: '橘子',value: 15},
                    { name: '榴莲',value: 20 },
                    { name: '山竹',value: 15 },
                    { name: '哈密瓜',value: 10 },
                    { name: '三华李',value: 8 }
                ],
                
            // 初始化echarts的动画效果
                animationType: 'scale',
                animationEasing: 'elasticOut',
                animationDelay: function (idx) {
                    return Math.random() * 200;
                }
            },
            {
                name:'中心圆',
                radius: ['0%', '38%'],
                center: ['30%', '50%'],
                type: 'pie',
                color:"#ffb980",  //内圆颜色
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false
                    }
                },
                animation: false,
                tooltip: {
                    show: false
                },
                data: [{
                    value: 1,

                }],
            },
            {
                name: '外边框',
                type: 'pie',
                clockWise: false, //顺时加载
                hoverAnimation: false, //鼠标移入变大
                center: ['30%', '50%'],
                radius: ['73%', '73%'],
                label: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: 9,
                    name: '',
                    itemStyle: {
                        normal: {
                            borderWidth: 2,
                            borderColor: '#2ec7c9'
                        }
                    }
                }]
            },
        ]
    }
Echarts是一个使用JavaScript实现的开源可视化库,它可以在网页中展示丰富的表类型。在Echarts中,例(legend)是用于展示不同系列的标记符号、颜色和名称,以及帮助用户进行例切换的功能组件。有时为了满足复杂的展示需求,例可以实现多层嵌套效果。 要实现Echarts例的多层嵌套,可以通过配置例中的`data`数组来达到目的。在这个数组中,每一项可以设置为一个对象,对象中可以包含`name`、`icon`和`text`等属性。对于多层嵌套例,可以通过在`data`中嵌套数组来表示不同的层级关系。 下面是一个简单的示例代码来说明如何设置多层嵌套例: ```javascript option = { legend: { data: [ { name: '第一层例1', icon: 'circle', text: '类别A', // 这里嵌套下一层级的例数组 items: [ { name: '第二层例1_1', icon: 'rect', text: '子类别A1' }, { name: '第二层例1_2', icon: 'triangle', text: '子类别A2' } ] }, { name: '第一层例2', icon: 'circle', text: '类别B', // 同样可以嵌套下一层级的例数组 items: [ { name: '第二层例2_1', icon: 'rect', text: '子类别B1' } ] } ] }, // ... 其他配置项 ... }; ``` 在上述代码中,`legend`中的`data`数组包含了两层例的配置。每个例项可以配置`name`、`icon`和`text`等属性,如果要表示下一层级的例,则在其下嵌套一个`items`数组,其中可以包含更多的例项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值