可以通过设置 title 的 textStyle 属性中的 textAlign 属性来实现饼图 title 居中对齐。

示例代码如下:

option = {
    title: {
        text: '饼图标题',
        textStyle: {
            fontSize: 18,
            fontWeight: 'bold',
            textAlign: 'center' // 设置居中对齐
        },
        left: 'center' // 设置标题位置居中
    },
    series: [
        {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            data: [
                {value: 335, name: '直接访问'},
                {value: 310, name: '邮件营销'},
                {value: 234, name: '联盟广告'},
                {value: 135, name: '视频广告'},
                {value: 1548, name: '搜索引擎'}
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};

其中,textStyle 中的 textAlign 属性设置为 'center',表示居中对齐;title 的位置通过设置 left 属性为 'center',也设置为居中。这样就可以实现饼图 title 的居中对齐。

Echarts 饼图标题居中对齐方法

原文地址: https://www.cveoy.top/t/topic/lDjz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录