【eCharts】echarts饼状图数据重叠导致指示线及显示文字重叠解决

转载自:https://www.cnblogs.com/minjh/p/9081893.html   先看他的,再看我的,不看我的也行

1. 解决前

 

2.解决后

3.代码

function makePie(id, title, name, data, show) {
    if (!show) {
        show = false;
    }
    var myChart = echarts.init(document.getElementById(id));
    var option = {
        title: {
			show:false,
            text: title,
            top: 2,
            left: '20',
			textStyle: {fontSize: 14,color:'#767676',fontWeight:600,fontFamily:'Microsoft Yahei'},
			
        },
        tooltip: {
            trigger: 'item',
			textStyle: {fontSize: 12,fontFamily:'Microsoft Yahei'},
            formatter: function (params) {
                return params.data.name + ":<br/>" + fmoneyf(params.data.value, 0) + "(" + params.percent + "%)";
            }
        },
        legend: {
            // type: 'scroll',
			orient:'vertical',
			top:80,
			y:'middle',
			height:'60%',
            right: getValueFromJson(data, 'name').length > 6 ? 0 : 5,
		    textStyle: {fontSize: 12,color:'#848484'},
			icon:'circle',
            data: getValueFromJson(data, 'name')
        },
        series: [
            {
                name: name,
                x: 'left',  
                y: 'center', 
                type: 'pie',
				center:['50%', '60%'],
                //radius: getValueFromJson(data, 'name').length > 6 ?  ['40%', '84px'] :  ['46%','90px'],
				 radius: '55%',
                avoidLabelOverlap: true,
                minAngle: 5,
                label: {
                	align: 'left',
                	normal: {
                        show: show,
						lineHeight:30,
						textStyle: {fontFamily:'Microsoft Yahei'},
						formatter(v) {
                            let text = Math.round(v.percent)+'%' + '' + v.name
                            if(text.length <= 8)
                            {
                                return text;
                            }else if(text.length > 8 && text.length <= 16){
                                return text = `${text.slice(0,8)}\n${text.slice(8)}`
                            }else if(text.length > 16 && text.length <= 24){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16)}`
                            }else if(text.length > 24 && text.length <= 30){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16,24)}\n${text.slice(24)}`
                            }else if(text.length > 30){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16,24)}\n${text.slice(24,30)}\n${text.slice(30)}`
                            }
                        },
						rich: {  
							color1: {  
								color: '#000000',
								fontSize: 14,
								lineHeight:12,
								fontWeight:600
							},  
							color2: {  
								color: '#848484'  ,
								fontSize: 12,
							}  
						},  
                    }, emphasis: {
                        show: !show,
						textStyle: {fontSize: 12,color:'#000000',fontFamily:'Microsoft Yahei'},
                        formatter: function (params) {
                            return params.data.name + ": " + fmoneyf(params.data.value, 0) + "(" + params.percent + "%)";
                        }
                    }
                },
				
				labelLine:{
					length:10,
					length2:100,
					lineStyle:{
						color:'#848484',
						
					}
				},
                data: data,
                color:getValueFromJson(data, 'color'),
            }
        ]
    };
    myChart.setOption(option);
}

4.主要代码段:

series: [
            {
                name: name,
                x: 'left',  
                y: 'center', 
                type: 'pie',
				center:['50%', '60%'],
                //radius: getValueFromJson(data, 'name').length > 6 ?  ['40%', '84px'] :  ['46%','90px'],
				 radius: '55%',
                avoidLabelOverlap: true,
                minAngle: 5,
                label: {
                	align: 'left',
                	normal: {
                        show: show,
						lineHeight:30,
						textStyle: {fontFamily:'Microsoft Yahei'},
						formatter(v) {//此方法为核心代码,解决问题
                            let text = Math.round(v.percent)+'%' + '' + v.name
                            if(text.length <= 8)
                            {
                                return text;
                            }else if(text.length > 8 && text.length <= 16){
                                return text = `${text.slice(0,8)}\n${text.slice(8)}`
                            }else if(text.length > 16 && text.length <= 24){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16)}`
                            }else if(text.length > 24 && text.length <= 30){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16,24)}\n${text.slice(24)}`
                            }else if(text.length > 30){
                                return text = `${text.slice(0,8)}\n${text.slice(8,16)}\n${text.slice(16,24)}\n${text.slice(24,30)}\n${text.slice(30)}`
                            }
                        },
						rich: {  
							color1: {  
								color: '#000000',
								fontSize: 14,
								lineHeight:12,
								fontWeight:600
							},  
							color2: {  
								color: '#848484'  ,
								fontSize: 12,
							}  
						},  
                    }, emphasis: {
                        show: !show,
						textStyle: {fontSize: 12,color:'#000000',fontFamily:'Microsoft Yahei'},
                        formatter: function (params) {
                            return params.data.name + ": " + fmoneyf(params.data.value, 0) + "(" + params.percent + "%)";
                        }
                    }
                },

ps:转载的

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值