以下效果实现使用的echarts版本为 4.X
const labelItemArr = [];
for (let i = 0; i < 100; ++i) {
labelItemArr.push({
value: 1,
name: i,
itemStyle: {
normal: {
color: i < 75 ? '#EB4B4B' : '#ccc' } }
}, {
value: 3,
name: '',
itemStyle: {
normal: {
label: {
show: false },
labelLine: {
show: false },
color: 'rgba(0, 0, 0, 0)',
borderColor: 'rgba(0, 0, 0, 0)',
borderWidth: 0
}
}
});
}
option = {
title: [{
text: '75%',
x: '50%',
y: '45%',
textAlign: 'center',
textStyle: {
fontSize: '30',
fontWeight: '600',
color: 'rgba(0,0,0,0.90)',
textAlign: 'center',
},
}, {
text: '在线率',
left: '50%',
top: '52%',
textAlign: 'center',
textStyle: {
fontSize: '18',
fontWeight: '400',
color: 'rgba(0,0,0,0.40)',
textAlign: 'center',
},
}],
polar: {
radius: ['61%', '57%'],
center: ['50%', '50%'],
},
angleAxis: {
max: 100,
show: false,
startAngle: 0,
},
radiusAxis: {
type: 'category',
show: true,
axisLabel: {
show: false },
axisLine: {
show: false },
axisTick: {
show: false },
},
series: [
{
hoverAnimation: false,
type: 'pie',
z: 2,
data: labelItemArr,
radius: ['68%', '75%'],
zlevel: -2,
label: {
normal: {
position: 'inside',
show: false,
}
},
},
{
type: 'pie',
radius: ['56%', '60%'],
center: ['50%', '50%'],
data: [{
hoverOffset: 1,
value: 75,
name: '',
itemStyle: {
color: '#EB4B4B ' },
label: {
show: false },
labelLine: {
normal: {
smooth: true,
lineStyle: {
width: 0
}
}
},
hoverAnimation: false,
}, {
label: {
show: false },
labelLine: {
normal: {
smooth: true,
lineStyle: {
width: 0 }
}
},
value: 100-75,
hoverAnimation: false,
itemStyle: {
color: '#ccc',
},
}]
},
]
};
option = {
color: ['#EB4B4B', 'rgb(245,245,245)'],
title: [{
text: '75%',
x: '50%',
y: '45%',
textAlign: 'center',
textStyle: {
fontSize: '40',
fontWeight: '500',
color: 'rgba(0,0,0,0.90)',
textAlign: 'center',
},
}, {
text: '使用率',
left: '50%',
top: '52%',
textAlign: 'center',
textStyle: {
fontSize: '16',
fontWeight: '400',
color: 'rgba(0,0,0,0.40)',
textAlign: 'center',
},
}],
polar: {
radius: ['75%', '60%'],
center: ['50%', '50%'],
},
angleAxis: {
max: 100,
show: false,
startAngle: 0,
},
radiusAxis: {
type: 'category',
show: true,
axisLabel: {
show: false,
},
axisLine: {
show: false,
},
axisTick: {
show: false
},
},
series: [
{
name: '',
type: 'bar',
roundCap: true,
barWidth: 60,
showBackground: true,
data: [75],
coordinateSystem: 'polar',
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
offset: 0,
color: '#EB4B4B'
}, {
offset: 1,
color: '#F47F7F'
}]),
}
}
},
]
};
最近项目画图比较多,之前用echarts用的都比较简单,最近参考社区中共享的echarts图之后,才发现自己使用的太死板,还是要多多的学习,继续多研究 echarts 的这些配置项,灵活使用。
欢迎大家多分享,相互学习!
学到老,活到老