Skip to content

Combo Chart (Bar and Line) for React

A React combo chart that draws bars and lines on one shared y-axis, such as a daily count with its rolling average. Pass data as readonly ChartRow[]: one object per category: the index key plus one number per series key.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/combo-chart.json

Orders per day

  • Orders
  • 7-day average
Use left and right arrow keys to read values.

  • ComboChart
  • ComboTable
  • comboLegend
  • indexSeries
  • defaultComboChartLabels
  • +3 more

Bars and their average

Same unit, one axis. The line draws across the bars once they have grown, with a surface halo so it stays readable where it crosses them.

Orders per day

Last 14 days

  • Orders
  • 7-day average

Files to copy

11 folders · 25 files · 4 packages
From theme/src/
  • components/charts/{combo-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/combo-chart.jsonRegistry item: combo-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Indexed: different units, one axis

Revenue (dollars), users and tickets (counts) can't share a value axis, and two axes would let the chart say anything. indexed rebases every series to 100 at its first value, so the axis reads “how much has each grown?”. The tooltip keeps the actual values.

Growth since November

Indexed to November = 100 for each series

  • Revenue
  • Active users
  • Support tickets

Stacked bars and a target

stacked stacks the bar series; the line is a target in the same unit. The tooltip adds the stack's total.

Customers vs target

  • New
  • Returning
  • Target

Edge cases

One category still gets a properly sized bar and a dot for the line (a line needs two points); no data keeps the chart's footprint.

One day

  • Orders
  • 7-day average

No data

No orders yet

ComboChart props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneOne object per category: the index key plus one number per series key.
index (required)stringNoneKey of the category in each row (e.g. "month").
series (required)readonly ComboSeries[]NoneBars and lines on ONE y-axis: they must share a unit (e.g. orders per day and their 7-day average). For measures with different units, set indexed instead of reaching for a second axis.
stackedbooleanfalseStack the bar series instead of grouping them side by side. Ignored when indexed (index values don't add up).
indexedbooleanfalseRe-base every series to the same starting point (its first non-zero value = indexBase), so measures of different units share one honest axis: "how has each changed?". A series that starts negative is rebased on its absolute value, so up still means up.
indexBasenumber100The value every series starts from when indexed.
heightnumber280Height of the chart in px; the width follows the container.
format((n: number) => string)formatCompactFormats raw values (tooltip; the axis too unless indexed).
formatIndex((n: number) => string)defaultFormatIndexFormats indexed values (axis and tooltip) when indexed.
emptyStateReactNodeNoneShown when there is nothing to plot.
patternsbooleantrue when there are more than 3 bar seriesTell the bar series apart without colour (hatch fills; the first bar series stays solid).
labelsPartial<ComboChartLabels>defaultComboChartLabelsEvery other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultComboChartLabels. All 5 keys of ComboChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
comboLegend(series)LegendItem[]NoneLegend items: swatches for bars, line keys for lines.
indexSeries(data, keys, base?)number[][]NoneThe indexed values the chart plots.
ComboChartLabels keys and English defaults (5)
Pass any key in labels; the rest keep the defaults of defaultComboChartLabels.
KeyEnglish default
totalTotal
noDataNo data
instructionsUse left and right arrow keys to read values.
touchHintTap a column to read its values.
indexedFromactual

ComboTable props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneTakes the same rows as the chart.
index (required)stringNoneKey of each row that names its category.
series (required)readonly ComboSeries[]NoneThe same series as the chart (bars and lines).
stackedbooleanfalseMatch the chart: adds a Total column (the sum of the bar series).
format((n: number) => string)formatCompactFormats the actual values (an indexed chart's table shows the real data, not the index).
indexLabelstringindexSets the header of the first column.
captionstringNoneVisually hidden caption naming the table (also names its scroll region).
labelsPartial<Pick<ComboChartLabels, "total" | "noData">>defaultComboChartLabelsOverride the "Total" column header and the empty text. Every other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultComboChartLabels. All 2 keys of ComboChartLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
←/→Previous / next category.
Home/EndJump to the first / last category.
EscapeClear the reading.

Accessibility

  • The chart is a focusable figure named by its aria-label (the chart title), with a one-line reading hint as its description and, inside a ChartCard with a table view, aria-details pointing at that table; moving through it announces each value politely, once. Each move announces every series' value.
  • ComboTable is the table view: pair it with ChartCard's table prop (Chart / Table tabs) so every value can be read without color or sight.
  • Reduced motion: the bars and the line appear at their final values and data changes jump instead of morphing.

All exports on this page

  • ComboChart — Bars and lines on one chart: give each series type: "bar" or type: "line".
  • ComboTable — The table view of a combo chart: the actual values of every series (headed by a swatch for bars, a line key for lines).
  • comboLegend — Legend items for a combo chart: a swatch for bar series, a line key for line series.
  • defaultComboChartLabels — The built-in English strings of ComboChart; spread it into your own labels and change what you need.
  • indexSeries — Rebase each series so its first non-zero value equals base: base + change / |first| x base.

When to use the combo chart

  • Use it as a bar and line chart when a volume and a rate belong on one chart, such as orders as bars with a conversion line, or daily signups as bars with their 7-day average as a line.
  • Use stacked to stack the bar series, for example revenue split by plan with a target line over it, while the line series keeps its own mark type per series.
  • Use indexed when the series have different units, like revenue and sessions: each is rebased to indexBase (default 100) so the chart answers how much each has changed.
  • Skip it when every series is the same mark type, where Bar chart or Line chart is simpler, or when you are tempted to add a second y-axis, which this chart deliberately does not offer.
  • Pair it with ChartCard and ComboTable, a ChartLegend built with comboLegend to name the bar and line series, and a SegmentedControl that flips indexed on and off.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .