echarts 饼图中如何隐藏value为0的数据
在网上查找了很多个各式各样的echarts中隐藏饼图value为0的数据的方法。很多都是从lable和lableLine下手。
这里我介绍一种简介快准狠的方式。
这里使用的是4.2.1的版本。
原效果图如下。
需要实现的效果
代码如下:先引入echarts
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
option = {
// title: {
// text: '圆环图的例子',
// left: 'center',
// top: 'center'
// },
//设置中间文字,如果需要换行,可以设置为数组
graphic:[
{
type:'text',
left:"center",
top:'40%',
style:{
text:['2021年度总资产'],
fill:'#888888',
textAlign:'center',
font:'14px Microsoft YaHei'
}
},
{
type:'text',
left:"center",
top:'50%',
style:{
text:'1000,000,00',
fill:'#c14e4e',
textAlign:'center',
font:'14px Microsoft YaHei',
fontWeight:'bold'
}
}
],
color:['rgb(186,110,61)','rgb(245,166,35)','rgb(233,145,0)','rgb(245,166,35)','#8d6327','#573504'],
//点击提示
tooltip:{
trigger:'item',
show:true,
formatter:'{a} <br/>{b} : {c} ({d}%)',
},
series: [
{
type: 'pie',
stillShowZeroSum: false,
name:'资金占比',
hoverAnimation:false,//hover是item放大,默认true
startAngle:50,//起始角度 默认为正上方90
radius: ['40%','70%'],
center:["50%","50%"],
itemStyle:{
emphasis:{//设置高亮的扇区和标签样式
shadowBlur:10,
shadowOffsetX:0,
shadowColor:'rgba(30,14,255,0.5)'
}
},
labelLine:{
show:true,
length:10,
length2:70
},
label:{
position:'outer',
show:true,
formatter:'{b}\n\n{d}%',
color:"green",
rich:{
b:{
lineHegiht:20
},
c:{
lineHeight:20
}
},
},
data: [
{
value: 53,
name: '直接访问'
},
{
value: 90,
name: '联盟广告' },
{
value: 20,
name: '搜索引擎'
},
{
value:'0',
name:'多多',
},
{
value:40,
name:'大黄'
}
]
}
]
};
// 使用刚指定的配置项和数据显示图表。
option.series[0].data.map((item,index)=>{
if(item.value==="0"){
item.value=''
}
return item
})
myChart.setOption(option);
喜欢的点个赞呗。