diff --git a/.changeset/stacked-combo-bars.md b/.changeset/stacked-combo-bars.md
new file mode 100644
index 00000000000..98184745d17
--- /dev/null
+++ b/.changeset/stacked-combo-bars.md
@@ -0,0 +1,5 @@
+---
+"@agent-native/toolkit": patch
+---
+
+Fix stacked bar series in combo charts while preserving independent target lines.
diff --git a/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.spec.tsx b/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.spec.tsx
index f8eedb68dff..adb4dc94246 100644
--- a/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.spec.tsx
+++ b/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.spec.tsx
@@ -67,8 +67,21 @@ describe("DashboardPanelChart", () => {
{ configurable: true, value },
);
}
- HTMLElement.prototype.getBoundingClientRect = () =>
- ({ ...CHART_SIZE, top: 0, left: 0, right: 640, bottom: 320 }) as DOMRect;
+ HTMLElement.prototype.getBoundingClientRect = function () {
+ if (this.id === "recharts_measurement_span") {
+ return {
+ width: this.textContent.length * 7,
+ height: 12,
+ } as DOMRect;
+ }
+ return {
+ ...CHART_SIZE,
+ top: 0,
+ left: 0,
+ right: 640,
+ bottom: 320,
+ } as DOMRect;
+ };
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
@@ -108,6 +121,254 @@ describe("DashboardPanelChart", () => {
},
);
+ it("stacks combo bars under a target line on its own axis and groups them by default", async () => {
+ const rows = [
+ { day: "2026-10-11", north: 30, south: 20, target: 500 },
+ { day: "2026-10-12", north: 40, south: 30, target: 1000 },
+ ];
+ const config = {
+ xKey: "day",
+ yKeys: ["north", "south", "target"],
+ barKeys: ["north", "south"],
+ rightYKeys: ["target"],
+ };
+ const rectangles = () =>
+ [...container.querySelectorAll(".recharts-bar-rectangle path")].map(
+ (path) => ({
+ x: Number(path.getAttribute("x")),
+ y: Number(path.getAttribute("y")),
+ width: Number(path.getAttribute("width")),
+ height: Number(path.getAttribute("height")),
+ }),
+ );
+
+ await render(
+ ,
+ );
+ const stacked = rectangles();
+ expect(stacked).toHaveLength(4);
+ const [northFirst, northSecond, southFirst] = stacked;
+ expect(northFirst.height).toBeGreaterThan(0);
+ expect(southFirst.height).toBeGreaterThan(0);
+ expect(northFirst.x).toBeCloseTo(southFirst.x);
+ expect(northFirst.width).toBeCloseTo(southFirst.width);
+ expect(southFirst.y + southFirst.height).toBeCloseTo(northFirst.y);
+ const targetLine = container
+ .querySelector(".recharts-line-curve")
+ ?.getAttribute("d");
+ const points = targetLine?.match(/^M([\d.]+),([\d.]+)L([\d.]+),([\d.]+)$/);
+ if (!points) throw new Error("Missing target line");
+ const [, x1, y1, x2, y2] = points.map(Number);
+ const grid = [
+ ...container.querySelectorAll(".recharts-cartesian-grid-horizontal line"),
+ ].map((line) => Number(line.getAttribute("y1")));
+ expect(grid).toHaveLength(2);
+ const [top, bottom] = grid;
+ expect(container.querySelectorAll(".recharts-yAxis")).toHaveLength(2);
+ expect(x1).toBeCloseTo(northFirst.x + northFirst.width / 2);
+ expect(x2).toBeCloseTo(northSecond.x + northSecond.width / 2);
+ expect(y1).toBeCloseTo((top + bottom) / 2);
+ expect(y2).toBeCloseTo(top);
+
+ await render(
+ ,
+ );
+ const grouped = rectangles();
+ expect(grouped).toHaveLength(4);
+ const [groupNorth, , groupSouth] = grouped;
+ expect(groupNorth.x).not.toBeCloseTo(groupSouth.x);
+ expect(groupNorth.y + groupNorth.height).toBeCloseTo(
+ groupSouth.y + groupSouth.height,
+ );
+ expect(
+ container.querySelector(".recharts-line-curve")?.getAttribute("d"),
+ ).toBe(targetLine);
+ });
+
+ it("stacks positive and negative combo bars on opposite sides of zero", async () => {
+ const config = {
+ xKey: "day",
+ yKeys: ["positive", "negative", "morePositive", "moreNegative", "target"],
+ barKeys: ["positive", "negative", "morePositive", "moreNegative"],
+ };
+ const rows = [
+ {
+ day: "2026-10-11",
+ positive: 30,
+ negative: -20,
+ morePositive: 10,
+ moreNegative: -10,
+ target: 5,
+ },
+ ];
+ const bars = () =>
+ [...container.querySelectorAll(".recharts-bar-rectangle path")].map(
+ (path) => {
+ const y = Number(path.getAttribute("y"));
+ const height = Number(path.getAttribute("height"));
+ return {
+ x: Number(path.getAttribute("x")),
+ y: Math.min(y, y + height),
+ height: Math.abs(height),
+ };
+ },
+ );
+
+ await render(
+ ,
+ );
+ const [positive, negative, morePositive, moreNegative] = bars();
+ expect(bars()).toHaveLength(4);
+ expect(positive.height).toBeGreaterThan(0);
+ expect(negative.height).toBeGreaterThan(0);
+ expect(morePositive.height).toBeGreaterThan(0);
+ expect(moreNegative.height).toBeGreaterThan(0);
+ expect(positive.x).toBeCloseTo(negative.x);
+ expect(negative.y).toBeCloseTo(positive.y + positive.height);
+ expect(morePositive.y + morePositive.height).toBeCloseTo(positive.y);
+ expect(moreNegative.y).toBeCloseTo(negative.y + negative.height);
+
+ await render(
+ ,
+ );
+ const [groupedPositive, groupedNegative] = bars();
+ expect(groupedPositive.x).not.toBeCloseTo(groupedNegative.x);
+ expect(groupedNegative.y).toBeCloseTo(
+ groupedPositive.y + groupedPositive.height,
+ );
+ });
+
+ it("positions stacks on different value axes side by side", async () => {
+ await render(
+ ,
+ );
+ const bars = [
+ ...container.querySelectorAll(".recharts-bar-rectangle path"),
+ ].map((path) => ({
+ x: Number(path.getAttribute("x")),
+ y: Number(path.getAttribute("y")),
+ width: Number(path.getAttribute("width")),
+ height: Number(path.getAttribute("height")),
+ }));
+ expect(bars).toHaveLength(4);
+ const [north, south, east, west] = bars;
+ expect(north.x).toBeCloseTo(south.x);
+ expect(south.y + south.height).toBeCloseTo(north.y);
+ expect(east.x).toBeCloseTo(west.x);
+ expect(west.y + west.height).toBeCloseTo(east.y);
+ expect(north.x + north.width).toBeLessThanOrEqual(east.x);
+ });
+
+ it("sizes duration axes to visible stacked bars and independent lines", async () => {
+ const hour = 3600;
+ const config = {
+ xKey: "day",
+ yKeys: ["north", "south", "east", "west", "target"],
+ barKeys: ["north", "south", "east", "west"],
+ rightYKeys: ["east", "west", "target"],
+ yFormatter: "duration" as const,
+ rightYFormatter: "duration" as const,
+ stacked: true,
+ };
+ const row = {
+ day: "2026-10-11",
+ north: 6 * hour,
+ south: 6 * hour,
+ east: 12 * hour,
+ west: 12 * hour,
+ target: 15 * hour,
+ };
+ await render(
+ ,
+ );
+ const labels = () =>
+ [...container.querySelectorAll(".recharts-yAxis-tick-labels")].map(
+ (axis) =>
+ [...axis.querySelectorAll(".recharts-cartesian-axis-tick-value")].map(
+ (tick) => tick.textContent,
+ ),
+ );
+ expect(labels()).toEqual([
+ ["0 sec", "3 hours", "6 hours", "9 hours", "12 hours"],
+ ["0 sec", "6 hours", "12 hours", "18 hours", "24 hours"],
+ ]);
+ await render(
+ ,
+ );
+ expect(labels()[1]).toEqual(["0 sec", "12 hours", "24 hours", "36 hours"]);
+ const south = container.querySelector(
+ '[data-chart-legend-item="south"]',
+ );
+ if (!south) throw new Error("Missing south legend item");
+ await act(async () => south.click());
+ expect(labels()[0]).toEqual(["0 sec", "2 hours", "4 hours", "6 hours"]);
+ });
+
+ it("uses the same duration scale as stacked bars without stacking the line", async () => {
+ const hour = 3600;
+ const rows = [
+ { day: "2026-10-11", north: 6 * hour, south: 6 * hour, target: 3 * hour },
+ ];
+ const config = {
+ xKey: "day",
+ yKeys: ["north", "south", "target"],
+ barKeys: ["north", "south"],
+ yFormatter: "duration" as const,
+ };
+ const labels = () =>
+ [
+ ...container.querySelectorAll(
+ ".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value",
+ ),
+ ].map((tick) => tick.textContent);
+
+ await render(
+ ,
+ );
+ expect(labels()).toEqual([
+ "0 sec",
+ "3 hours",
+ "6 hours",
+ "9 hours",
+ "12 hours",
+ ]);
+
+ await render(
+ ,
+ );
+ expect(labels()).toEqual(["0 sec", "2 hours", "4 hours", "6 hours"]);
+ });
+
it("dashes the day the rows were read as unfinished, not today", async () => {
const line = panel("line", { xKey: "day", yKeys: ["people"] });
await render();
diff --git a/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.tsx b/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.tsx
index 74a6fe045d9..dc13d2a1116 100644
--- a/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.tsx
+++ b/packages/toolkit/src/app/dashboard-charts/DashboardPanelChart.tsx
@@ -214,6 +214,7 @@ export function DashboardPanelChart({
colors={seriesColors}
yFormatter={yFormatter}
barKeys={panel.config?.barKeys ?? []}
+ stacked={panel.config?.stacked === true}
panel={panel}
onDatumClick={onDatumClick}
/>,
diff --git a/packages/toolkit/src/app/dashboard-charts/panel-chart.tsx b/packages/toolkit/src/app/dashboard-charts/panel-chart.tsx
index 3c3eb2db8a8..60092f7f15f 100644
--- a/packages/toolkit/src/app/dashboard-charts/panel-chart.tsx
+++ b/packages/toolkit/src/app/dashboard-charts/panel-chart.tsx
@@ -310,6 +310,7 @@ type ChartAxisValues = {
rows: Record[];
keys: string[];
stacked?: boolean | undefined;
+ stackedKeys?: ReadonlySet | undefined;
};
// Duration axes step in clean units ("6 hours") rather than the decimal
@@ -324,7 +325,7 @@ function durationAxisProps(values: ChartAxisValues, keys: string[]) {
for (const key of keys) {
const value = Number(row[key]);
if (!Number.isFinite(value)) continue;
- if (values.stacked) {
+ if (values.stacked || values.stackedKeys?.has(key)) {
if (value < 0) below += value;
else above += value;
} else {
@@ -3137,6 +3138,7 @@ export function ComboRenderer({
colors,
yFormatter,
barKeys,
+ stacked,
panel,
onDatumClick,
}: {
@@ -3146,6 +3148,7 @@ export function ComboRenderer({
colors: string[];
yFormatter?: ChartValueFormatter | undefined;
barKeys: string[];
+ stacked?: boolean;
panel: SqlPanel;
onDatumClick?: DatumClickHandler | undefined;
}) {
@@ -3225,6 +3228,7 @@ export function ComboRenderer({
{chartClick.locator}
@@ -3248,6 +3252,7 @@ export function ComboRenderer({
{renderChartYAxes(dualAxis, yFormatter, {
rows,
keys: yKeys.filter((key) => !hiddenKeys.has(key)),
+ stackedKeys: stacked ? barKeySet : undefined,
})}
,
diff --git a/templates/analytics/changelog/2026-11-20-stacked-combo-charts-now-display-bar-series-correctly-alongs.md b/templates/analytics/changelog/2026-11-20-stacked-combo-charts-now-display-bar-series-correctly-alongs.md
new file mode 100644
index 00000000000..a3f058fa0a0
--- /dev/null
+++ b/templates/analytics/changelog/2026-11-20-stacked-combo-charts-now-display-bar-series-correctly-alongs.md
@@ -0,0 +1,6 @@
+---
+type: fixed
+date: 2026-11-20
+---
+
+Stacked combo charts now display bar series correctly alongside target lines.