echarts动效饼图

let angle = 0; //角度,用来做简单的动画效果的
let value = 55.33;
let color = ['#fdd56a', '#fdb36a', '#fd866a', '#73ddff', '#73acff', '#34c98e', '#ef4f2e'];
let list = [
    {
        name: '站前1标',
        icon: 'circle',
        value: 10,
    },
    {
        name: '站前2标',
        icon: 'circle',
        value: 15,
    },
    {
        name: '站前3标',
        icon: 'circle',
        value: 12,
    },
    {
        name: '站前4标',
        icon: 'circle',
        value: 8,
    },
    {
        name: '站前5标',
        icon: 'circle',
        value: 16,
    },
    {
        name: '站前6标',
        icon: 'circle',
        value: 24,
    },
    {
        name: '站前7标',
        icon: 'circle',
        value: 18,
    },
];
option = {
    // backgroundColor: '#061740',

    legend: {
        type: 'plain',
        right: 0,
        bottom: '10%',
        x: 'center',
        data: list,
        itemWidth: 16,
        itemHeight: 16,
        itemGap: 10,
        icon: 'roundRect',
        textStyle: {
            color: '#333',
            padding: [10, 1, 10, 0],
        },
        selectedMode: false,
    },
    series: [
        {
            name: 'ring5',
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                return {
                    type: 'arc',
                    shape: {
                        cx: api.getWidth() / 2,
                        cy: api.getHeight() / 2,
                        r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.6,
                        startAngle: ((0 + angle) * Math.PI) / 180,
                        endAngle: ((90 + angle) * Math.PI) / 180,
                    },
                    style: {
                        stroke: '#fdcb9b',
                        fill: 'transparent',
                        lineWidth: 1.5,
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: 'ring5',
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                return {
                    type: 'arc',
                    shape: {
                        cx: api.getWidth() / 2,
                        cy: api.getHeight() / 2,
                        r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.6,
                        startAngle: ((180 + angle) * Math.PI) / 180,
                        endAngle: ((270 + angle) * Math.PI) / 180,
                    },
                    style: {
                        stroke: '#fdcb9b',
                        fill: 'transparent',
                        lineWidth: 1.5,
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: 'ring5',
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                return {
                    type: 'arc',
                    shape: {
                        cx: api.getWidth() / 2,
                        cy: api.getHeight() / 2,
                        r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65,
                        startAngle: ((270 + -angle) * Math.PI) / 180,
                        endAngle: ((40 + -angle) * Math.PI) / 180,
                    },
                    style: {
                        stroke: '#fdcb9b',
                        fill: 'transparent',
                        lineWidth: 1.5,
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: 'ring5',
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                return {
                    type: 'arc',
                    shape: {
                        cx: api.getWidth() / 2,
                        cy: api.getHeight() / 2,
                        r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65,
                        startAngle: ((90 + -angle) * Math.PI) / 180,
                        endAngle: ((220 + -angle) * Math.PI) / 180,
                    },
                    style: {
                        stroke: '#fdcb9b',
                        fill: 'transparent',
                        lineWidth: 1.5,
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: 'ring5',
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                let x0 = api.getWidth() / 2;
                let y0 = api.getHeight() / 2;
                let r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65;
                let point = getCirlPoint(x0, y0, r, 90 + -angle);
                return {
                    type: 'circle',
                    shape: {
                        cx: point.x,
                        cy: point.y,
                        r: 4,
                    },
                    style: {
                        stroke: '#fdcb9b', //粉
                        fill: '#fdcb9b',
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: 'ring5', //绿点
            type: 'custom',
            coordinateSystem: 'none',
            renderItem: function (params, api) {
                let x0 = api.getWidth() / 2;
                let y0 = api.getHeight() / 2;
                let r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65;
                let point = getCirlPoint(x0, y0, r, 270 + -angle);
                return {
                    type: 'circle',
                    shape: {
                        cx: point.x,
                        cy: point.y,
                        r: 4,
                    },
                    style: {
                        stroke: '#fdcb9b', //绿
                        fill: '#fdcb9b',
                    },
                    silent: true,
                };
            },
            data: [0],
        },
        {
            name: '吃猪肉频率',
            type: 'pie',
            radius: ['58%', '35%'],
            silent: true,
            clockwise: true,
            startAngle: 180,
            z: 0,
            zlevel: 0,
            color: color,
            itemStyle: {
                normal: {
                    borderColor: 'rgba(255,255,255)',
                    borderWidth: '15',
                },
            },
            label: {
                normal: {
                    position: 'inside',
                    formatter: function (params) {
                        return params.percent + '%';
                    },

                    color: '#fff',
                    fontSize: 10,
                },
            },
            data: list,
        },
        {
            type: 'pie',
            zlevel: 3,
            silent: true,
            radius: ['30%', '31%'],
            //  center: [index * 34 + 15.5 + '%', '45%'],
            label: {
                normal: {
                    show: true,
                    position: 'center',
                    color: '#4c4a4a',
                    formatter: '{total|' +178 + '}' + '\n\r' + '{active|总数}',
                    rich: {
                        total: {
                            fontSize: 35,
                            fontFamily: '微软雅黑',
                            color: '#454c5c',
                        },
                        active: {
                            fontFamily: '微软雅黑',
                            fontSize: 16,
                            color: '#6c7a89',
                            lineHeight: 30,
                        },
                    },
                },
                emphasis: {
                    //中间文字显示
                    show: true,
                },
            },
            labelLine: {
                normal: {
                    show: false,
                },
            },
            data: dotArr(),
        },
    ],
};

function dotArr() {
    let dataArr = [];
    for (var i = 0; i < 80; i++) {
        if (i % 2 === 0) {
            dataArr.push({
                name: (i + 1).toString(),
                value: 1,
                itemStyle: {
                    normal: {
                        color: '#0CD3DB',
                        borderWidth: 1,
                        borderColor: '#0CD3DB',
                    },
                },
            });
        } else {
            dataArr.push({
                name: (i + 1).toString(),
                value: 2,
                itemStyle: {
                    normal: {
                        color: 'rgba(0,0,0,0)',
                        borderWidth: 0,
                        borderColor: 'rgba(0,0,0,0)',
                    },
                },
            });
        }
    }
    return dataArr;
}

//获取圆上面某点的坐标(x0,y0表示坐标,r半径,angle角度)
function getCirlPoint(x0, y0, r, angle) {
    let x1 = x0 + r * Math.cos((angle * Math.PI) / 180);
    let y1 = y0 + r * Math.sin((angle * Math.PI) / 180);
    return {
        x: x1,
        y: y1,
    };
}

function draw() {
    angle = angle + 3;
    myChart.setOption(option, true);
    //window.requestAnimationFrame(draw);
}

setInterval(function () {
    //用setInterval做动画感觉有问题
    draw();
}, 100);

在这里插入图片描述

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值