如何让饼图中间文字大小自适应图表?

如何让饼图中间文字大小自适应图表?
今天在项目中遇到echarts饼图中间文字居中的需求,显示用了title:{}中添加文本,辅助left,top位置来显示也能实现,

但是后面发现不能中间数字变化后无法适应位置,这样写会固定死位置,不灵活。

关键代码:

   {
                name: '',
                z: 100,
                type: 'gauge',
                radius: '-50%',
                center: [`30%`, `50%`],
                // 配置中间的数字
                detail: {
                    // 调节数字位置
                    offsetCenter: [-1,-15],
                    fontSize: 30,
                    fontFamily:'PangMenZhengDao' ,
                    color: '#D8E9FF',
                },
                pointer: {
                    show: false,
                },
                axisTick: {
                    show: false,
                },
                axisLine: {
                    show: false,
                },
                splitLine: {
                    show: false,
                },
                axisLabel: {
                    show: false,
                },
                // 中间的字和数字 数据
                data: [
                    {
                        value: value,
                        name:''
                    },
                ],
            }

直接用这个达不到我想要的结果,没法给下面文字定义style,我还是结合了title,把数字下面的文字固定死了,如果有大神指教那就太好了。
也是在网上反复查,最终测试可以了,代码如下:
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: data,
animationType: ‘scale’,
animationEasing: ‘elasticOut’,
animationDelay: function (idx) {
return Math.random() * 200;
}
},
{
name:‘中心’,
radius: [‘0%’, ‘38%’],
center: [‘30%’, ‘50%’],
type: ‘pie’,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: “rgba(15, 55, 73, 1)” },
{ offset: 1, color: “rgba(9, 32, 41, .59)” },
]), //内圆颜色
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
                }
            },
            tooltip:{show:false},
            data: [{
                value: 9,
                name: '',
                itemStyle: {
                    normal: {
                        borderWidth: 2,
                        borderColor: '#194b54'
                    }
                }
            }]
        },
        {
            name: '',
            z: 100,
            type: 'gauge',
            radius: '-50%',
            center: [`30%`, `50%`],
            // 配置中间的数字
            detail: {
                // 调节数字位置
                offsetCenter: [-1,-15],
                fontSize: 30,
                fontFamily:'PangMenZhengDao' ,
                color: '#D8E9FF',
            },
            pointer: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: false,
            },
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            // 中间的字和数字 数据
            data: [
                {
                    value: value,
                    name:''
                },
            ],
        }
    ]

贴个图:
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值