Skip to documentation content

Combo Chart

Plot bars and lines on one category axis, with an optional second value axis for a different unit.

Bars with a line on a second axis

Overview

Use a combo chart when two related measures share a category axis but answer different questions: an amount drawn as bars, and a rate or trend drawn as a line. Revenue with conversion rate, rainfall with temperature, and tickets opened with tickets resolved are typical pairs.

When the two measures use different units, put the line on a right-hand axis. The right axis picks ticks that land on the left axis's grid lines, so one set of dashed lines serves both scales. Reach for a second axis only when the units really differ: two axes on the same unit invite readers to compare heights that are not comparable.

Anatomy

ComboChart owns the data, the category axis, selection, the brush, and loading. Bar and Line parts add series; each one names the axis it is measured against with yAxisId. Add one YAxis per side you want labelled, and optional Grid, Legend, Tooltip, and Brush parts.

Lines always draw above bars, so a trend is never hidden behind a column. Bars and lines share one axis tooltip that lists every series at the hovered category.

Accessibility

Two axes make a chart harder to read precisely, so name each axis with label or a unit in its tickFormatter, and give the chart a clear ariaLabel. The canvas exposes only that name: pair the chart with a summary or table when readers need exact values. The tooltip, legend toggles, and brush are pointer-operated; do not make them the only way to reach information.

Installation

npm install honestui

Usage

import { ComboChart, type ChartConfig } from "honestui/charts";
<ComboChart data={data} config={chartConfig} xDataKey="month">
  <ComboChart.Grid />
  <ComboChart.XAxis />
  <ComboChart.YAxis yAxisId="left" tickFormatter={(value) => `$${value / 1000}k`} />
  <ComboChart.YAxis yAxisId="right" tickFormatter={(value) => `${value}%`} />
  <ComboChart.Legend isClickable />
  <ComboChart.Tooltip />
  <ComboChart.Bar dataKey="revenue" isClickable />
  <ComboChart.Line dataKey="conversion" yAxisId="right" isClickable>
    <ComboChart.Dot variant="border" />
  </ComboChart.Line>
</ComboChart>

Give the tooltip a valueFormatter when the series use different units. It receives the series key, so each row can carry its own unit:

<ComboChart.Tooltip
  valueFormatter={(value, key) => (key === "conversion" ? `${value}%` : `$${value}`)}
/>

Examples

Stacked Bars

stackType='stacked'

stackType="stacked" stacks every bar series that shares an axis, so the line can show a total, a target, or an outcome against the composition. Lines are never stacked.

Brush

ComboChart.Brush

Add ComboChart.Brush to zoom a long series. The preview strip shows the first bar series; dragging the selection filters bars and lines together.

Reference Lines and Comparison

ReferenceLine and compareDataKey

ComboChart.ReferenceLine, ReferenceArea, and ReferenceDot mark targets and periods; they are measured against the left value axis. compareDataKey on a Bar draws last period's value as a tick across the column, and on a Line as a faded dashed line on the same axis as the line. The tooltip adds the earlier value and the change under each compared row. See Reference Lines and Period Comparison.

Synced Crosshair

syncId="share-day"

Charts that share a syncId show their tooltip at the same category when any one of them is hovered, here a candlestick chart above a combo chart of trading activity. Add ComboChart.Zoom to zoom and pan inside the plot; it shares its window with the brush. See Synced Crosshair and Brush and Zoom.

Loading State

isLoading='true'

isLoading keeps the layout with a neutral bar and line silhouette and the same loading label as the other Honest UI charts.

API Reference

ComboChart
PropTypeDefaultDescription
data*TData[]–

One row per category.

config*ChartConfig–

Labels and theme colors for every bar and line key. See Chart Config.

xDataKeykeyof TData & string–

The category field. Falls back to the XAxis dataKey, then the first field that is not a series.

stackTypedefault|stacked"default"

Places bars side by side or stacks the bars on each axis.

barRadiusnumber2

Corner radius for bars. A stacked column rounds only its top segment.

curveTypelinear|smooth|step"smooth"

Default curve for every line.

barGapnumber–

Gap between grouped bars, in pixels.

barCategoryGapnumber–

Gap between categories, in pixels.

animationbooleantrue

Plays the intro animation. Reduced-motion preferences turn it off.

defaultSelectedDataKeystring | nullnull

The series selected on first render.

onSelectionChange(key: string | null) => void–

Fires when a clickable bar, line, or legend item is selected or cleared.

isLoadingbooleanfalse

Shows the loading silhouette and label.

syncIdstring–

Charts with the same id move their crosshair and tooltip together.

ariaLabelstring–

Accessible name for the canvas. A description of the series is generated when omitted.

chartOptionsRecord<string, unknown>–

Escape hatch merged over the generated ECharts option.

Bar
PropTypeDefaultDescription
dataKey*string–

The series field and config key.

variantdefault|gradient|hatched|duotone"default"

Bar fill, matching the Bar Chart variants of the same name.

radiusnumber–

Overrides barRadius for this series.

yAxisIdleft|right"left"

The value axis the bar is measured against.

isClickablebooleanfalse

Lets a click select the series.

enableHoverHighlightbooleanfalse

Dims the other bars while one is hovered.

compareDataKeystring–

A field holding the same measure for an earlier period, drawn as a tick across the bar and compared in the tooltip. Stacked bars compare in the tooltip only.

Line
PropTypeDefaultDescription
dataKey*string–

The series field and config key.

yAxisIdleft|right"left"

The value axis the line is measured against.

curveTypelinear|smooth|step–

Overrides the root curveType.

strokeVariantsolid|dashed"solid"

Dashes suit targets and forecasts.

strokeWidthnumber1.5

Line width in pixels.

connectNullsbooleanfalse

Bridges missing values instead of leaving a gap.

compareDataKeystring–

A field holding the same measure for an earlier period, drawn as a faded dashed line and compared in the tooltip.

isClickablebooleanfalse

Lets a click select the series.

childrenReactNode–

ComboChart.Dot for resting points and ComboChart.ActiveDot for the hovered point. Both take a variant of "default", "border", "colored-border", or "ping".

YAxis
PropTypeDefaultDescription
yAxisIdleft|right"left"

Which side this axis describes. Add one per side.

tickFormatter(value: number, index: number) => string–

Formats tick labels.

labelstring–

Axis title.

minnumber–

Fixes the lower bound.

maxnumber–

Fixes the upper bound.

hideDotsbooleanfalse

Hides the tick dots.

XAxis
PropTypeDefaultDescription
dataKeystring–

The category field, if not set on the root.

tickFormatter(value: string, index: number) => string–

Formats category labels.

labelstring–

Axis title.

hideDotsbooleanfalse

Hides the tick dots.

Tooltip
PropTypeDefaultDescription
variantdefault|frosted-glass"default"

Tooltip surface.

roundnesssm|md|lg|xl"lg"

Tooltip corner radius.

positionfixed|variable"variable"

Pins the tooltip to the top or lets it follow the pointer.

cursorbooleantrue

Draws the dashed line at the hovered category.

valueFormatter(value: number, dataKey: string) => string–

Formats each row. Receives the series key.

labelFormatter(label: string) => string–

Formats the category shown as the tooltip title, such as a date.

defaultIndexnumber–

Opens the tooltip at a category after mount.

Legend
PropTypeDefaultDescription
variantLegendVariant"rounded-square"

Indicator shape, shared with the other charts.

alignleft|center|right"right"

Horizontal alignment.

verticalAligntop|middle|bottom"top"

Vertical placement.

isClickablebooleanfalse

Lets a legend item select its series.

Brush
PropTypeDefaultDescription
heightnumber56

Height of the preview strip in pixels.

formatLabel(value: string, index: number) => string–

Formats the range labels shown while the brush is hovered.

onChange(range: { startIndex: number; endIndex: number }) => void–

Fires when the selected range changes.

Zoom, ReferenceLine, ReferenceArea, ReferenceDot

ComboChart.Zoom takes the props listed in Brush and Zoom. The reference parts take the props listed in Reference Lines; a y value is read on the left value axis.