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/APITypeDefaultDescription
datareadonly T[]requiredOne row per category.
categoryKeystring or number field of TrequiredField identifying each category.
ariaLabelstringrequiredAccessible 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.
legendboolean | { align?, placement? }shown for 2+ seriesSeries legend; items toggle their series.
tooltipbooleantrueHover and keyboard tooltip.
gridbooleantrueLeft-axis grid lines.
valueDomain, valueTicks[number, number], number[]fitted, includes zeroLeft axis extent and ticks.
formatValue(value: number) => stringgrouped numberLeft axis and its tooltip rows.
rightValueDomain, rightValueTicks[number, number], number[]fitted, includes zeroRight axis extent and ticks.
formatRightValue(value: number) => stringformatValueRight axis and its tooltip rows.
formatCategory(value: string | number) => stringStringCategory ticks and tooltip titles.
emptyMessageReactNode"No data to display"Shown when no valid values exist.
Chart host propssee Chart-height, initialWidth, ariaDescription, tooltipFooter, renderTooltipBody, callbacks, className, style.
createComboChartDefinition(options)function-Same options plus hiddenSeries; returns an extensible TanStack definition.
ComboChartBarSeries, ComboChartLineSeries, ComboChartDatum, ComboChartDefinitiontypes-Exported for typed series and builders.

Accessibility

  • Provide a meaningful ariaLabel that 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.

On this page