ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

自动旋转的饼图(echarts)

2022-01-14 17:33:08  阅读:193  来源: 互联网

标签:angle name idx list value 旋转 values 自动 echarts


const list=[
    {value: 1048, name: '搜索引擎'},
    {value: 735, name: '直接访问'},
    {value: 580, name: '邮件营销'},
    {value: 484, name: '联盟广告'},
    {value: 300, name: '视频广告'}    
]
const values=list.map(o=>o.value)
option = {
    title: {
        text: '某站点用户访问来源',
        subtext: '纯属虚构',
        left: 'center'
    },
    selectedOffset:100,
    clockwise:true,
    tooltip: {
        trigger: 'item'
    },
    legend: {
        orient: 'vertical',
        left: 'left',
    },
    series: [
        {
            name: '访问来源',
            type: 'pie',
            // roseType:true,
            startAngle:152,
            radius: ['25%', '40%'],
            data: list,
            itemStyle:{
                // shadowOffsetX: 10,
                borderWidth:20,
                borderColor:"pink",
                decal:{
                    symbolSize:0.2
                } 
            },
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};

const sum=list=>list.reduce((a,b)=>a+b,0)

var idx =0
var angle=0
setInterval(()=>{
    idx++
    if(idx>=list.length){
        idx=0
    }
    angle=(360*(sum(values.slice(0,idx))+values[idx]/2)/sum(values)+90)%360
    console.log(currentAngle,angle)
    myChart.setOption({
        series:[{
            startAngle:angle,
            selectedOffset:0,
            selectedMode:true,
            // datasetIndex:idx,
            select:{
                focus: 'series',
                label:{
                    show:true,
                },
                itemStyle: {
                    shadowBlur: 10,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
            
        }]
    });
    myChart.dispatchAction({
        type: 'select',
        dataIndex:idx,
    });
},5000)

myChart.on('click',(args)=>{
    console.log(args,angle)
    const index=args.dataIndex
    angle=(360*(sum(values.slice(0,index))+values[index]/2)/sum(values)+90)%360
    //点击后自动旋转的时候就在指定的扇面后旋转
    idx = index
    myChart.setOption({
        series:[{
            startAngle:angle
        }]
    })
})

 

标签:angle,name,idx,list,value,旋转,values,自动,echarts
来源: https://www.cnblogs.com/llcdbk/p/15802748.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有