ComboChart
Bars and lines over one category axis, with an optional second value axis.
stable
Quick Preview
Revenue and Occupancy
Rent collected vs. units let - Jan-Jun
Usage
import { ComboChart } from "@giddaa-housing/ui/combo-chart";
<ComboChart
data={[
{ month: "Jan", revenue: 18.4, occupancy: 0.72 },
{ month: "Feb", revenue: 21.2, occupancy: 0.78 },
]}
categoryKey="month"
bars={[{ key: "revenue", label: "Revenue" }]}
lines={[{ key: "occupancy", label: "Occupancy", axis: "right" }]}
formatValue={(value) => `₦${value}m`}
formatRightValue={(value) => `${Math.round(value * 100)}%`}
rightValueDomain={[0, 1]}
rightValueTicks={[0, 0.5, 1]}
ariaLabel="Monthly revenue with occupancy rate"
/>ComboChart draws bars and lines over one category axis, sharing data and
categoryKey like BarChart. A line with
axis: "right" reads against a second value axis formatted by
formatRightValue; each tooltip row uses its own axis's formatter. Bars take the
first palette slots and lines continue the sequence. Use a second axis only when
the two measures have different units, and label both.
Examples
Bars with a right-axis line
Revenue and Occupancy
Rent collected vs. units let - Jan-Jun
Stacked bars with a target line
barLayout="stacked" stacks several bars; a line on the left axis reads as a
target against the stack total.
Collections vs. Target
Rent and fees against plan - Jan-Jun
Props
| Prop/API | Type | Default | Description |
|---|---|---|---|
data | readonly T[] | required | One row per category. |
categoryKey | string or number field of T | required | Field identifying each category. |
ariaLabel | string | required | Accessible chart name. |
bars | { key, label?, color? }[] | [] | Bar series, on the left axis. |
lines | { key, label?, color?, axis? }[] | [] | Line series; axis is "left" (default) or "right". |
barLayout | "grouped" | "stacked" | "grouped" | How several bar series share a category. |
size | "sm" | "md" | "lg" | inherited, otherwise "md" | Plot height and type. |
legend | boolean | { align?, placement? } | shown for 2+ series | Series legend; items toggle their series. |
tooltip | boolean | true | Hover and keyboard tooltip. |
grid | boolean | true | Left-axis grid lines. |
valueDomain, valueTicks | [number, number], number[] | fitted, includes zero | Left axis extent and ticks. |
formatValue | (value: number) => string | grouped number | Left axis and its tooltip rows. |
rightValueDomain, rightValueTicks | [number, number], number[] | fitted, includes zero | Right axis extent and ticks. |
formatRightValue | (value: number) => string | formatValue | Right axis and its tooltip rows. |
formatCategory | (value: string | number) => string | String | Category ticks and tooltip titles. |
emptyMessage | ReactNode | "No data to display" | Shown when no valid values exist. |
| Chart host props | see Chart | - | height, initialWidth, ariaDescription, tooltipFooter, renderTooltipBody, callbacks, className, style. |
createComboChartDefinition(options) | function | - | Same options plus hiddenSeries; returns an extensible TanStack definition. |
ComboChartBarSeries, ComboChartLineSeries, ComboChartDatum, ComboChartDefinition | types | - | Exported for typed series and builders. |
Accessibility
- Provide a meaningful
ariaLabelthat names both measures; focus the chart and use arrow keys to move between categories. - With a right axis, format both axes with units so values are never read against the wrong scale.
- Keep the legend; bars and lines are named by text, not color alone.