style(图表): 优化柱状图动画与视觉样式

- 启用平滑动画提升交互体验
- 调整颜色方案增强视觉层次
- 添加阴影效果和间距提升可读性
- 优化标签位置和字体大小
This commit is contained in:
2026-04-01 15:13:23 +08:00
parent 7b505ec4aa
commit 9bc58c6270

View File

@ -40,11 +40,17 @@ function buildOption(list: BarDatum[]): ECOption {
const correct = list.map(i => i.correct) const correct = list.map(i => i.correct)
return { return {
// 用动画,避免频繁刷新时的抖动 // 用动画,让柱子变化更平滑
animation: false, animation: true,
animationDuration: 800,
animationEasing: 'cubicOut',
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { type: 'shadow' }, axisPointer: { type: 'shadow' },
backgroundColor: 'rgba(255, 255, 255, 0.9)',
borderColor: '#3b82f6',
borderWidth: 1,
textStyle: { color: '#1e3a8a' },
}, },
legend: { legend: {
data: ['答题数量', '预估得分'], data: ['答题数量', '预估得分'],
@ -52,17 +58,18 @@ function buildOption(list: BarDatum[]): ECOption {
right: 0, right: 0,
icon: 'circle', icon: 'circle',
textStyle: { textStyle: {
color: '#666', color: '#64748b',
fontSize: 12,
}, },
}, },
grid: { left: 16, right: 16, top: 40, bottom: 0, containLabel: true }, grid: { left: 16, right: 16, top: 70, bottom: 0, containLabel: true },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: categories, data: categories,
axisTick: { show: false }, // 隐藏 x 轴刻度线 axisTick: { show: false }, // 隐藏 x 轴刻度线
axisLine: { show: false }, // 隐藏 x 轴线 axisLine: { show: false }, // 隐藏 x 轴线
axisLabel: { axisLabel: {
color: '#003366', // 深蓝色字体 color: '#1e3a8a', // 深蓝色字体
fontWeight: 'bold', fontWeight: 'bold',
fontSize: 14, fontSize: 14,
margin: 16, margin: 16,
@ -82,6 +89,7 @@ function buildOption(list: BarDatum[]): ECOption {
type: 'bar', type: 'bar',
data: total, data: total,
barWidth: 24, barWidth: 24,
barGap: '40%', // 柱子间的间隙
itemStyle: { itemStyle: {
// 从上到下:浅蓝 -> 深蓝 // 从上到下:浅蓝 -> 深蓝
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
@ -89,14 +97,17 @@ function buildOption(list: BarDatum[]): ECOption {
{ offset: 1, color: '#3b82f6' }, // blue-500 (底部深色) { offset: 1, color: '#3b82f6' }, // blue-500 (底部深色)
]), ]),
borderRadius: [4, 4, 0, 0], borderRadius: [4, 4, 0, 0],
shadowBlur: 10,
shadowColor: 'rgba(59, 130, 246, 0.2)',
shadowOffsetY: 4,
}, },
label: { label: {
show: true, show: true,
position: 'top', position: 'top',
color: '#003366', // 深蓝色 color: '#1e3a8a', // 深蓝色
fontWeight: 'bold', fontWeight: 'bold',
fontSize: 18, fontSize: 16,
offset: [0, 2], offset: [0, -4],
}, },
}, },
{ {
@ -111,14 +122,17 @@ function buildOption(list: BarDatum[]): ECOption {
{ offset: 1, color: '#f97316' }, // orange-500 (底部深色) { offset: 1, color: '#f97316' }, // orange-500 (底部深色)
]), ]),
borderRadius: [4, 4, 0, 0], borderRadius: [4, 4, 0, 0],
shadowBlur: 10,
shadowColor: 'rgba(249, 115, 22, 0.2)',
shadowOffsetY: 4,
}, },
label: { label: {
show: true, show: true,
position: 'top', position: 'top',
color: '#ea580c', // orange-600 color: '#ea580c', // orange-600
fontWeight: 'bold', fontWeight: 'bold',
fontSize: 18, fontSize: 16,
offset: [0, 2], offset: [0, -4],
}, },
}, },
], ],