【前端可视化】Echarts 实现环形饼图外层带阴影效果配置
效果展示
实现代码
原理主要还是用两个饼图嵌套,外侧做阴影,内层放数据。配置比较复杂,怕下次遇到就做个记录吧。
initEcharts() {
const myChart = echarts.init(this.$refs.chart)
const userScore = this.userScore.slice(0, this.userScore.length - 1)
let option = {
tooltip: {
trigger: 'item',
renderMode: 'html',
formatter: "<div style='color: #000000;font-style: normal;font-weight: 500;font-size: 13PX;line-height: 18PX;'>{b0}</div><div style='color: #0a9391;margin-top:10PX;'>Score +{c0}%</div>",
borderColor: '#fff',
padding: 12,
extraCssText: 'box-shadow: 0PX 2PX 4PX rgba(0, 0, 0, 0.25);',
},
legend: {
show: false,
},
title: [{
text: `{a|Your Score}\n{b|${userScore}}{c|%}`,
top: 'center',
left: 'center',
textStyle: {
fontFamily: 'PingFang SC',
fontStyle: 'normal',
fontWeight: 500,
rich: {
a: {
color: '#47bfaf',
padding: [0, 0, 10, 0],
fontSize: 13,
},
b: {
color: '#47bfaf',
fontSize: 40,
},
c: {
color: '#47bfaf',
fontSize: 18,
},
},
},
}, ],
series: [{
name: 'border',
type: 'pie',
clockWise: false,
radius: '75%',
center: ['50%', '50%'],
animation: false,
data: [{
value: 0,
color: '#fff',
label: {
show: false,
},
labelLine: {
show: false,
},
emphasis: {
disabled: true,
},
select: {
disabled: true,
},
tooltip: {
show: false,
},
itemStyle: {
color: '#fff',
shadowColor: 'rgba(0, 0, 0, 0.2)',
shadowBlur: 15,
shadowOffsetX: 2,
shadowOffsetY: 2,
},
}, ],
},
{
name: '',
type: 'pie',
radius: ['35%', '65%'],
center: ['50%', '50%'],
avoidLabelOverlap: false,
selectedMode: false,
select: {
itemStyle: {
color: '#f9b762',
},
},
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
emphasis: {
color: '#f9b762',
},
borderRadius: 7,
},
label: {
show: false,
position: 'center',
},
emphasis: {
label: {
show: false,
},
},
labelLine: {
show: false,
},
data: this.echartsData,
},
],
}
option && myChart.setOption(option)
},
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
2020-06-16 【Node】npm 报错:ERR! notarget No matching version found for event-stream@3.3.6