echarts -环形图高亮时中间文字设置(三)

var myChart4 = null;
var currentIndex = -1;
var chart4Interval;
var data = [{"areaId":null,"areaName":"xxxx轮胎有限公司","deviceCode":"dht5084416002","deviceName":"5-1-MN002","alarmCount":"1385","allCount":"20146","alarmRate":"6.87"},{"areaId":null,"areaName":"xxxx化工公司","deviceCode":"ccc5087717013","deviceName":"废气总排口","alarmCount":"1244","allCount":"14928","alarmRate":"8.33"}];

function deviceAlarmRateOfTotal(data){
        if(myChart4!=null){
            myChart4.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
                dataIndex: currentIndex
            });
            myChart4.dispatchAction({
                type: 'hideTip'
            });
        }
        currentIndex = -1;
        if(chart4Interval!=null){
            clearInterval( chart4Interval);
        }
        myChart4 = echarts.init(document.getElementById("chart_msc4"));
        var arry = [];
        for(var i=0;i<data.length;i++){
            arry[i] = {value:data[i].alarmCount, name:data[i].deviceName};
        }
        var option = {
            tooltip: {
                trigger: 'item',
                formatter: function(params,ticket,calback){
                    var str = '<div  style="text-align:center;width:5em;color:#fff;background:transparent;border-color:#0e335f;margin:-5px; transition: all 2s;z-index:100000000;" id="toolTipBox" >'+
                       '<p style="font-size:size*1.2;margin:0px;font-weight:bold;">'+params.percent+'%</p>'+
                        '<p style="font-size:size*0.8;margin:0px 0px 0px 0px; color:#fff">'+params.name+'</p></div>';
                 
                    return str;
                },
                position:function(point,params,dom,rect,size){
                    var marginW = Math.ceil(size.contentSize[0]/2);
                    var marginH = Math.ceil(size.contentSize[1]/2);
                    dom.style.marginLeft = "-" + marginW + 'px';
                    dom.style.marginTop = '-' + marginH + "px";
                    return ['50%','50%'];

                },
                alwaysShowContent:true,
                backgroundColor:"transparent",
                textStyle:{
                    fontSize:size,
                    color:'#0e335f'
                }
            },
            color:['#234591','#90ac45',"#24feb4",'#1bb2d8','#066660','#88b0bb',"#2b65bc","#75a0e1"],
            series: [
                {
                    name: '设备报警占比',
                    type: 'pie',
                    center: ['50%', '50%'], // 饼图的圆心坐标
                    radius: ['70%', '80%'],
                    avoidLabelOverlap: false,
                    label: {
                        normal: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            show: false,
                            textStyle: {
                                fontSize: 10,
                                color:"#0e335f"
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data:arry.slice(0,15)
                }
             ]
        };
        myChart4.setOption(option,true);

        chart4Interval =  setInterval(function(){
            var dataLength= option.series[0].data.length;
            // 取消之前高亮的图形
            myChart4.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
                dataIndex: currentIndex
            });
            currentIndex = (currentIndex + 1) % dataLength;
            // 高亮当前图形
            myChart4.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: currentIndex
            });
            // 显示 tooltip
            myChart4.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: currentIndex
            });

            if(currentIndex>dataLength){
                currentIndex = -1;
            }

            $("#toolTipBox").animate({},function(){
                $("#toolTipBox").css({'height':'38px','transform':'rotate(360deg)'});
            });
        }, 5000);
    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Echarts 中实现世界地发光和设置高亮,可以使用 Echarts 的特效和地组件。 首先,要在 Echarts 中引入地组件和特效组件,可以在 Echarts 的官网下载相应的组件库。然后,通过配置 Echarts 的 option 参数来设置的样式和特效。 下面是一个简单的示例代码,演示了如何在 Echarts 中实现世界地发光和设置高亮: ```javascript // 引入地组件和特效组件 echarts.registerMap('world', worldMapData); echarts.registerMap('china', chinaMapData); echarts.registerVisual(echarts.graphic.clipPointsByRect); echarts.registerVisual(echarts.graphic.clipRectByRect); echarts.registerVisual(echarts.graphic.clipPointsByRect); echarts.registerVisual(echarts.graphic.clipRectByRect); echarts.registerVisual(echarts.graphic.clipPointsByRect); echarts.registerVisual(echarts.graphic.clipRectByRect); echarts.registerVisual(echarts.graphic.clipPointsByRect); echarts.registerVisual(echarts.graphic.clipRectByRect); // 配置 option 参数 var option = { tooltip: { show: true, trigger: 'item' }, visualMap: { type: 'piecewise', splitNumber: 6, inverse: true, pieces: [ {min: 10000}, {min: 5000, max: 9999}, {min: 1000, max: 4999}, {min: 500, max: 999}, {min: 100, max: 499}, {max: 99} ], inRange: { color: ['#fef0d9', '#fdcc8a', '#fc8d59', '#e34a33', '#b30000'] } }, series: [ { name: '世界地', type: 'map', mapType: 'world', roam: true, itemStyle: { normal: { areaColor: '#323c48', borderColor: '#111' }, emphasis: { areaColor: '#2a333d', borderColor: '#111', borderWidth: 1 } }, label: { normal: { show: false }, emphasis: { show: false } }, data: [ {name: 'China', value: 100000}, {name: 'United States', value: 20000}, {name: 'Russia', value: 8000}, {name: 'Australia', value: 5000}, {name: 'Canada', value: 1000}, {name: 'Brazil', value: 500}, {name: 'Argentina', value: 200}, {name: 'Chile', value: 100}, {name: 'Mexico', value: 50}, {name: 'India', value: 20}, {name: 'Pakistan', value: 10}, {name: 'Bangladesh', value: 5}, {name: 'Japan', value: 1} ] } ], // 添加特效 graphic: [ { type: 'circle', shape: { cx: 100, cy: 100, r: 50 }, style: { fill: '#fff' }, zlevel: 100 } ] }; ``` 在上面的代码中,我们配置了一个世界地,并且设置了数据值,通过 visualMap 来设置颜色区间和分段数目。在 series 中,我们设置了地的样式和数据,通过 itemStyle 来设置选中的样式。 最后,我们通过 graphic 参数来添加特效,上面的代码添加了一个圆形特效。您可以根据自己的需求来添加不同的特效效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值