效果如上
外环代码:
series: [
{
name: "产品金额",
type: "pie",
radius: ["75%", "85%"],
center: props.center,
padAngle: 5, // 饼图扇形之间的间距
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 0
},
label: {
show: false,
position: "center",
fontWeight: "bold"
},
emphasis: {
label: {
show: false,
fontSize: 18
}
},
labelLine: {
show: false
},
data: props.data
},
]
内环代码:
series:[
...外环代码,
{
name: "背景",
type: "pie",
radius: ["0%", "70%"], // 设置内环的半径
center: props.center,
data: [{ value: total, name: "产品金额" }],
itemStyle: {
color: new echarts.graphic.RadialGradient(0.5, 0.5, 1, [
{ offset: 0, color: "rgba(1, 71, 235, 0.20)" },
{ offset: 1, color: "rgba(2, 125, 247, 1)" }
]) // 设置内环的背景颜色
},
label: {
show: true,
position: "center",
formatter: params => {
return `{a|${params.value}}\n{b|元}`;
},
rich: {
a: {
fontSize: 24,
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: "rgba(138, 203, 255, 1)" },
{ offset: 1, color: "rgba(0, 74, 255, 1))" }
]).toString(),
fontWeight: "bold"
},
b: {
fontSize: 16,
color: "#fff",
padding: [5, 0, 0, 0]
}
}
},
labelLine: {
show: false
},
silent: true // 防止鼠标事件触发
}
]
右侧图例代码:
legend: {
orient: "vertical", // 显示方式 纵向
right: "0%",
top: 50,
width: 200,
textStyle: {
color: "#fff",
fontSize: 12
},
data: props.data.map(item => item.name), // 仅显示实际数据的图例项
formatter: name => {
const item = props.data.find(item => item.name === name);
const percentage = ((item.value / total) * 100).toFixed(2);
return `${name.padEnd(15, " ")}${percentage}%`;
}
},
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通