echarts 环形图鼠标悬停

var m2R2Data = [{
        value: 335,
        value1: 234,
        legendname: 'Ⅰ类',
        name: "Ⅰ类",
        itemStyle: {
            color: "#8d7fec"
        }
    },
    {
        value: 310,
        value1: 314,
        legendname: 'Ⅱ类',
        name: "Ⅱ类",
        itemStyle: {
            color: "#5085f2"
        }
    },
    {
        value: 234,
        value1: 235,
        legendname: 'Ⅲ类',
        name: "Ⅲ类",
        itemStyle: {
            color: "#e75fc3"
        }
    },
    {
        value: 154,
        value1: 213,
        legendname: 'Ⅳ类',
        name: "Ⅳ类",
        itemStyle: {
            color: "#f87be2"
        }
    },
    {
        value: 335,
        value1: 321,
        legendname: 'Ⅴ类',
        name: "Ⅴ类",
        itemStyle: {
            color: "#f2719a"
        }
    },

];

option = {
    title: [{
            text: '全网调控情况',
            textStyle: {
                fontSize: 16,
                color: "black"
            },
            left: "2%"
        },
        {
            text: '全网均温',
            subtext: 44.5 + '℃',
            textStyle: {
                fontSize: 15,
                color: "black"
            },
            subtextStyle: {
                fontSize: 20,
                color: 'black'
            },
            textAlign: "center",
            x: '34.5%',
            y: '44%',
        }
    ],
    tooltip: {
        trigger: 'item',
        formatter: function(parms) {
            var str = parms.seriesName + "</br>" +
                parms.marker + "" + parms.data.legendname + "</br>" +
                "当前温度:" + parms.data.value + "</br>" +
                "目标温度:" + parms.data.value1 + "</br>" +
                "占比:" + parms.percent + "%";
            return str;
        }
    },
    legend: {
        type: "scroll",
        orient: 'vertical',
        left: '65%',
        align: 'left',
        top: 'middle',
        textStyle: {
            color: '#8C8C8C'
        },

    },
    series: [{
        name: '全网调控情况',
        type: 'pie',
        center: ['35%', '50%'],
        radius: ['40%', '65%'],
        clockwise: false, //饼图的扇区是否是顺时针排布
        avoidLabelOverlap: false,
        itemStyle: { //图形样式
            normal: {
                borderColor: '#ffffff',
                borderWidth: 1,
            },
        },
        label: {
            normal: {
                show: true,
                position: 'outter',
                formatter: function(parms) {
                    return parms.data.legendname
                }
            }
        },
        labelLine: {
            normal: {
                length: 15,
                length2: 13,
                smooth: true,
            }
        },
        data: m2R2Data
    }]
};
    autoFn(m2R2Data.length)
    function autoFn(leng){
             var that = this
            //轮播效果
            var currentIndex = -1
           
            //  let myChart = echarts.getInstanceByDom(document.getElementById("chart-panel"))
            var dataLen =leng

            that.timer = setInterval(() => {
                //  计时器增加
                that.ai++

                if (that.ai == dataLen) {
                    that.ai = 1
                }
                 console.log(dataLen)
                // 取消之前高亮的图形
                myChart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                    dataIndex: currentIndex,
                })
                currentIndex = (currentIndex + 1) % dataLen
                // 高亮当前图形
                myChart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: currentIndex,
                })
                // 显示 tooltip
              myChart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: currentIndex,
                })
            }, 3000)










           
var count = 0;
var timeTicket = null;
var dataLength = option.series[0].data.length;
timeTicket && clearInterval(timeTicket);
timeTicket = setInterval(function() {
    myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
    });
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    count++;
}, 1000);

myChart.on('mouseover', function(params) {
    console.log(params)
    clearInterval(timeTicket);
     myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0
    });
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: params.dataIndex
    });    
    myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: params.dataIndex,
    });
});
myChart.on('mouseout', function(params) {
    timeTicket && clearInterval(timeTicket);
    timeTicket = setInterval(function() {
         myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
    });
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    count++;
    }, 1000);
});

    }
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

花归去

客官赏点吧

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

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

打赏作者

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

抵扣说明:

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

余额充值