Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
c2cb67a9
Commit
c2cb67a9
authored
Jan 29, 2026
by
水玉婷
Browse files
feat:修复折线图及柱状图数据展示问题
parent
b2f96e4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/views/components/ColumnChart.vue
View file @
c2cb67a9
...
...
@@ -493,7 +493,20 @@ const createSingleColumnOption = (chartConfig: any): echarts.EChartsOption => {
dataZoom
:
getDataZoomConfig
(
xAxisData
.
length
)
};
}
else
{
const
seriesData
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yField
]);
// 非分组模式下,需要对数据进行聚合,每个X轴数据点对应聚合后的值
const
seriesData
=
xAxisData
.
map
(
xValue
=>
{
// 找到对应X轴值的所有数据点
const
itemsForX
=
chartConfig
.
data
.
filter
((
item
:
any
)
=>
item
[
chartConfig
.
xField
]
===
xValue
);
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yField
])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
return
{
...
getBaseChartConfig
(
xAxisData
.
length
),
...
...
@@ -547,8 +560,41 @@ const createDualColumnOption = (chartConfig: any): echarts.EChartsOption => {
dataZoom
:
getDataZoomConfig
(
xAxisData
.
length
)
};
}
else
{
const
series1Data
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yFields
[
0
]]);
const
series2Data
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yFields
[
1
]]);
// 非分组模式下,需要对数据进行聚合,每个X轴数据点对应不同的指标值
// 首先按X轴值分组数据
const
groupedData
:
{
[
key
:
string
]:
any
[]
}
=
{};
chartConfig
.
data
.
forEach
((
item
:
any
)
=>
{
const
xValue
=
item
[
chartConfig
.
xField
];
if
(
!
groupedData
[
xValue
])
{
groupedData
[
xValue
]
=
[];
}
groupedData
[
xValue
].
push
(
item
);
});
// 为每个指标创建对应的数据数组,对同一个月的数据进行求和聚合
const
series1Data
=
xAxisData
.
map
(
xValue
=>
{
const
itemsForX
=
groupedData
[
xValue
]
||
[];
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yFields
[
0
]])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
const
series2Data
=
xAxisData
.
map
(
xValue
=>
{
const
itemsForX
=
groupedData
[
xValue
]
||
[];
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yFields
[
1
]])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
return
{
...
getBaseChartConfig
(
xAxisData
.
length
),
...
...
src/views/components/LineChart.vue
View file @
c2cb67a9
...
...
@@ -499,7 +499,20 @@ const createSingleLineOption = (chartConfig: any): echarts.EChartsOption => {
dataZoom
:
getDataZoomConfig
(
xAxisData
.
length
)
};
}
else
{
const
seriesData
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yField
]);
// 非分组模式下,需要对数据进行聚合,每个X轴数据点对应聚合后的值
const
seriesData
=
xAxisData
.
map
(
xValue
=>
{
// 找到对应X轴值的所有数据点
const
itemsForX
=
chartConfig
.
data
.
filter
((
item
:
any
)
=>
item
[
chartConfig
.
xField
]
===
xValue
);
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yField
])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
return
{
...
getBaseChartConfig
(),
...
...
@@ -551,8 +564,41 @@ const createDualLineOption = (chartConfig: any): echarts.EChartsOption => {
dataZoom
:
getDataZoomConfig
(
xAxisData
.
length
)
};
}
else
{
const
series1Data
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yFields
[
0
]]);
const
series2Data
=
chartConfig
.
data
.
map
((
item
:
any
)
=>
item
[
chartConfig
.
yFields
[
1
]]);
// 非分组模式下,需要对数据进行聚合,每个X轴数据点对应不同的指标值
// 首先按X轴值分组数据
const
groupedData
:
{
[
key
:
string
]:
any
[]
}
=
{};
chartConfig
.
data
.
forEach
((
item
:
any
)
=>
{
const
xValue
=
item
[
chartConfig
.
xField
];
if
(
!
groupedData
[
xValue
])
{
groupedData
[
xValue
]
=
[];
}
groupedData
[
xValue
].
push
(
item
);
});
// 为每个指标创建对应的数据数组,对同一个月的数据进行求和聚合
const
series1Data
=
xAxisData
.
map
(
xValue
=>
{
const
itemsForX
=
groupedData
[
xValue
]
||
[];
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yFields
[
0
]])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
const
series2Data
=
xAxisData
.
map
(
xValue
=>
{
const
itemsForX
=
groupedData
[
xValue
]
||
[];
// 对同一个月的数据进行求和聚合
if
(
itemsForX
.
length
>
0
)
{
return
itemsForX
.
reduce
((
sum
:
number
,
item
:
any
)
=>
{
const
value
=
Number
(
item
[
chartConfig
.
yFields
[
1
]])
||
0
;
return
sum
+
value
;
},
0
);
}
return
0
;
});
return
{
...
getBaseChartConfig
(),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment