美文网首页
百度Echarts实现环形包并包围标签效果

百度Echarts实现环形包并包围标签效果

作者: wwmin_ | 来源:发表于2020-07-29 16:34 被阅读0次

利用echarts中饼图的特性
相关API详见series-pie

echarts效果图

实现:

function aroundChart(id, name, number, color, unit) {
    var dom = document.getElementById(id);
    var chart = echarts.init(dom);
    var opt = {
        series: [{
            name: "",
            type: "pie",
            toolbox: {
                feature: {
                    saveAsImage: {
                        pixelRatio: 2
                    }
                }
            },
            radius: ["50%", "70%"],
            color: [color, "transparent"],
            startAngle: 225,
            label: {
                normal: {
                    show: false,
                    position: "center"
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data: [{
                value: 75,
                name: name,
                label: {
                    normal: {
                        show: true,
                        formatter: name + "\n\n\n",
                        textStyle: {
                            color: "#000",
                            fontSize: 12
                        }
                    }
                }
            }, {
                value: 25,
                name: number,
                label: {
                    normal: {
                        show: true,
                        formatter: number,
                        textStyle: {
                            color: color,
                            fontSize: 14
                        }
                    }
                }
            }, {
                value: 0,
                name: "%",
                label: {
                    normal: {
                        show: true,
                        formatter: "\n\n\n" + unit,
                        textStyle: {
                            color: "#000",
                            fontSize: 12
                        }
                    }
                }
            }]
        }]
    };
    chart.clear();
    chart.setOption(opt);
}

相关文章

网友评论

      本文标题:百度Echarts实现环形包并包围标签效果

      本文链接:https://www.haomeiwen.com/subject/affkrktx.html