Skip to content

Commit 864a4e9

Browse files
author
Roman Snapko
committed
Fix BarChart y-axis domain calculation for stacked bars
1 parent 5df2fff commit 864a4e9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/ui-components/src/ui/chart/bar-chart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ export function BarChart({
6161
const yAxisDomain = useMemo<[number, number]>(() => {
6262
let max = 0;
6363
for (const row of data) {
64+
const stackTotals: Record<string, number> = {};
6465
for (const bar of bars) {
6566
const v = Number(row[bar.dataKey] ?? 0);
66-
if (v > max) {
67-
max = v;
67+
const groupKey = bar.stackId ?? bar.dataKey;
68+
stackTotals[groupKey] = (stackTotals[groupKey] ?? 0) + v;
69+
}
70+
for (const total of Object.values(stackTotals)) {
71+
if (total > max) {
72+
max = total;
6873
}
6974
}
7075
}

0 commit comments

Comments
 (0)