echarts饼图

 

const payload = {
    id: 'left-center-1',
    title: '年龄占比',
    toolTip: true,
    data: {
        total: '197',
        data: ['1', '32', '57', '67', '40'],
        x: ['35岁以下', '35-40岁', '40-45岁', '45-50岁', '50岁以上'],
    },
};

data = [];

// const color = ['#2F7DF2', '#F9CA3C', '#2E5CF2', '#34E9A3', '#F63048', '#F97A3C', '#2FD9F2', '#A9DB32', '#6151F1'];
  const color = [
    "#6172D3",
    "#F5A539",
    "#FED969",
    "#469AE3",
     "#F97A3C",
    "#2FD9F2",
    "#A9DB32",
    "#6151F1",
  ];
payload.data.x.forEach((item, index) => {
    data.push({ value: payload.data.data[index], name: item, label: { color: color[index] } });
});

const tooltip = payload.toolTip !== undefined ? payload.toolTip : true;
let countdata = payload.data.data.reduce((a,b) => Number(a) + Number(b));
option = {
    // backgroundColor: 'transparent',
    backgroundColor: '#0f375f',
    grid: {
        left: 0,
        right: 0,
        bottom: 0,
        top: 0,
        containLabel: true,
    },
    tooltip: {
        show: tooltip,
        backgroundColor: 'rgba(9, 30, 60, 0.6)',
        extraCssText: 'box-shadow: 0 0 8px rgba(0, 128, 255, 0.27) inset;',
        borderWidth: 0,
        confine: false,
        appendToBody: true,
        textStyle: {
            color: '#fff',
            fontSize: 10,
        },
        // 轴触发提示才有效
        axisPointer: {
            type: 'shadow',
        },
        shadowStyle: {
            color: 'rgba(157, 168, 245, 0.1)',
        },
 
        formatter: function (parms) {
            var str = parms.seriesName + "</br>" +
                parms.marker + parms.name + " </br>" +
                "人数:" + parms.data.value + "</br>" +
                "占比:" + parms.percent + "%";
            return str;
        }
    },
    legend: {
        type: "scroll",
        // orient: "vertical",
        pageIconColor: "#76b9ff",
        pageIconInactiveColor: "#fff",
        pageTextStyle: {
            color: "#76b9ff",
            fontSize: 14,
        },
        show: true,
        // top: "-1%",
        right: "25%",
        bottom: "4%",
        // icon: "rect",
        // itemWidth: 10, // 图例标记的图形宽度。
        // itemHeight: 10, //  图例标记的图形高度。
        textStyle: {
            color: "#fff",
            fontSize: 12,
            // padding: [0, 8, 0, 8],
        },
    },
    series: [
        {
            name: payload.title,
            type: 'pie',
            radius: ['55%', '75%'],
            minAngle: 8,
            itemStyle: {
                color(params) {
                    return color[params.dataIndex];
                },
            },
            labelLine: {
                // length2: 55,
                length: 15,
                length2: 85,
                lineStyle: {
                    // type: "dashed",
                    width: 2,
                },
            },
            label: {
                position: 'outer',
                alignTo: 'none',
                bleedMargin: 15,
                formatter: ' {b}\n{a|{c}人} {b|{d}%} ',
                padding: -85,
                rich: {
                    a: {
                        padding: [18, 0, 5, 0],
                        // fontSize: 14,
                        color: '#fff',
                        lineHeight: 20,
                    },
                    b: {
                        padding: [18, 0, 5, 0],
                        lineHeight: 20,
                    },
                },
            },
            data,
        },
        {
            type: "gauge",
            zlevel: 1,
            // z: 198,
            splitNumber: 40,
            radius: "55%",
            center: ["50%", "50%"],
            startAngle: 90,
            endAngle: -269.9999,
            axisLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            splitLine: {
                show: true,
                length: 6,
                lineStyle: {
                    width: 3,
                    color: "rgba(108,173,202,1)",
                },
            },
            data: [
                {
                    value: countdata,
                    name: "总人数",
                    title: {
                        // 配置“家居总数”的样式
                        show: true,
                        fontSize: 20,
                        fontWeight: 700,
                        // fontFamily: fontFamily.fontFamily65W,
                        color: "#fff",
                        // offsetCenter: [0, "20%"],
                        offsetCenter: [-2, -17],
                    },
                },
            ],
            detail: {
                // 调节数字位置
                // offsetCenter: [-2, -17],
                offsetCenter: [0, "20%"],
                fontSize: 25,
                fontWeight: 700,
                // fontFamily: fontFamily.fontFamily95W,
                color: "#fff",
            },
            pointer: {
                show: false,
            },
            // detail: {
            //   show: 0,
            // },
        },
    ],
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花归去

客官赏点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值