Skip to content

Commit 82a4605

Browse files
committed
refine: 优化G2图表视觉效果,增强低数据量场景下的显示
## 折线图优化 - 加粗线条:2px 3px,线条更明显 - 增大数据点:4px 6px,更清晰 - 改变数据点样式:实心蓝色 + 白色边框 - 增强面积填充:透明度 15% 20% - 延长动画时间:800ms 1000ms - 添加数据点缩放弹出动画 ## 饼图优化 - 调整环形比例,更美观 - 简化标签:只显示百分比 - 加粗标签字体:14px + font-weight 600 - 添加白色扇区分隔线(3px) - 优化悬停效果:蓝色边框高亮 - 增强Tooltip:显示数量 + 百分比 ## 效果提升 - 即使只有2-3个数据点也清晰美观 - 统一蓝色主题,无渐变 - 流畅的动画过渡效果
1 parent a286c9b commit 82a4605

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

web/src/components/charts/G2LineChart.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ function initChart() {
5959
.encode('y', props.yField)
6060
.encode('shape', props.smooth ? 'smooth' : 'line')
6161
.style('stroke', props.color)
62-
.style('lineWidth', 2)
62+
.style('lineWidth', 3)
6363
.tooltip({
6464
title: (d) => d[props.xField],
6565
items: [(d) => ({ name: '访问量', value: d[props.yField] })]
6666
})
67-
.animate('enter', { type: 'pathIn', duration: 800 })
67+
.animate('enter', { type: 'pathIn', duration: 1000 })
6868
6969
// 面积填充
7070
chart
@@ -74,24 +74,25 @@ function initChart() {
7474
.encode('y', props.yField)
7575
.encode('shape', props.smooth ? 'smooth' : 'area')
7676
.style('fill', props.color)
77-
.style('fillOpacity', 0.15)
77+
.style('fillOpacity', 0.2)
7878
.tooltip(false)
79-
.animate('enter', { type: 'fadeIn', duration: 800 })
79+
.animate('enter', { type: 'fadeIn', duration: 1000 })
8080
81-
// 数据点
81+
// 数据点 - 增大尺寸,更明显
8282
chart
8383
.point()
8484
.data(props.data)
8585
.encode('x', props.xField)
8686
.encode('y', props.yField)
87-
.encode('size', 4)
87+
.encode('size', 6)
8888
.encode('shape', 'point')
89-
.style('fill', '#fff')
90-
.style('stroke', props.color)
91-
.style('lineWidth', 2)
89+
.style('fill', props.color)
90+
.style('stroke', '#fff')
91+
.style('lineWidth', 3)
9292
.tooltip(false)
93-
.state('active', { fill: props.color })
93+
.state('active', { r: 8 })
9494
.interaction('elementHighlight', true)
95+
.animate('enter', { type: 'scaleInY', duration: 800, delay: 500 })
9596
9697
// 坐标轴配置
9798
chart.axis('y', {

web/src/components/charts/G2PieChart.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function initChart() {
4747
height: props.height,
4848
})
4949
50-
chart.coordinate({ type: 'theta', outerRadius: 0.8, innerRadius: 0.5 })
50+
chart.coordinate({ type: 'theta', outerRadius: 0.75, innerRadius: 0.45 })
5151
5252
chart
5353
.interval()
@@ -58,25 +58,41 @@ function initChart() {
5858
.scale('color', { range: props.colors })
5959
.legend('color', {
6060
position: 'right',
61-
layout: { justifyContent: 'center' }
61+
layout: { justifyContent: 'center' },
62+
itemMarker: {
63+
symbol: 'circle',
64+
style: { r: 5 }
65+
}
6266
})
6367
.label({
6468
text: (d) => {
6569
const total = props.data.reduce((sum, item) => sum + item[props.valueField], 0)
6670
const percent = ((d[props.valueField] / total) * 100).toFixed(1)
67-
return `${d[props.labelField]}\n${percent}%`
71+
return `${percent}%`
6872
},
6973
position: 'outside',
70-
fontSize: 12,
71-
fill: '#64748b'
74+
fontSize: 14,
75+
fontWeight: 600,
76+
fill: '#334155',
77+
connectorDistance: 8,
78+
connectorStroke: '#cbd5e1',
79+
connectorStrokeWidth: 1
7280
})
7381
.tooltip({
7482
items: [(d) => ({
7583
name: d[props.labelField],
76-
value: d[props.valueField]
84+
value: d[props.valueField] + ' (' + ((d[props.valueField] / props.data.reduce((sum, item) => sum + item[props.valueField], 0)) * 100).toFixed(1) + '%)'
7785
})]
7886
})
79-
.animate('enter', { type: 'waveIn', duration: 800 })
87+
.style('stroke', '#fff')
88+
.style('lineWidth', 3)
89+
.animate('enter', { type: 'waveIn', duration: 1000 })
90+
.state('active', {
91+
style: {
92+
lineWidth: 4,
93+
stroke: '#2563eb'
94+
}
95+
})
8096
.interaction('elementHighlight', true)
8197
8298
chart.render()

0 commit comments

Comments
 (0)