# Combo Chart

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

Source: https://www.honestui.com/docs/charts/combo-chart/static

### Bars with a line on a second axis

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: Online store revenue and conversion rate
const data = [
  { month: "January", revenue: 18400, conversion: 2.1 },
  { month: "February", revenue: 21250, conversion: 2.4 },
  { month: "March", revenue: 19870, conversion: 2.2 },
  { month: "April", revenue: 24630, conversion: 2.7 },
  { month: "May", revenue: 27110, conversion: 2.9 },
  { month: "June", revenue: 25480, conversion: 2.6 },
  { month: "July", revenue: 29960, conversion: 3.1 },
  { month: "August", revenue: 31420, conversion: 3.3 },
  { month: "September", revenue: 28750, conversion: 3.0 },
  { month: "October", revenue: 33180, conversion: 3.4 },
  { month: "November", revenue: 39640, conversion: 3.9 },
  { month: "December", revenue: 42870, conversion: 4.2 },
];

const chartConfig = {
  revenue: {
    label: "Revenue",
    colors: { light: ["#2563eb"], dark: ["#3b82f6"] },
  },
  conversion: {
    label: "Conversion rate",
    colors: { light: ["#ea580c"], dark: ["#f97316"] },
  },
} satisfies ChartConfig;

export function ExampleComboChart() {
  return (
    <ComboChart data={data} config={chartConfig} xDataKey="month" className="h-full w-full p-4">
      <ComboChart.Grid />
      <ComboChart.XAxis tickFormatter={(value) => value.slice(0, 3)} />
      <ComboChart.YAxis yAxisId="left" tickFormatter={(value) => `$${value / 1000}k`} />
      <ComboChart.YAxis yAxisId="right" tickFormatter={(value) => `${value}%`} />
      <ComboChart.Legend isClickable />
      <ComboChart.Tooltip
        valueFormatter={(value, key) =>
          key === "conversion" ? `${value.toFixed(1)}%` : `$${value.toLocaleString()}`
        }
      />
      <ComboChart.Bar dataKey="revenue" isClickable />
      <ComboChart.Line dataKey="conversion" yAxisId="right" isClickable>
        <ComboChart.Dot variant="border" />
      </ComboChart.Line>
    </ComboChart>
  );
}

```

## Overview [#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 [#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 [#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 [#installation]

<CommandBlock commands="[&#x22;honestui&#x22;]" />

## Usage [#usage]

```tsx
import { ComboChart, type ChartConfig } from "honestui/charts";
```

```tsx
<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:

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

## Examples [#examples]

### Stacked Bars [#stacked-bars]

### stackType='stacked'

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: Support tickets by channel against tickets resolved
const data = [
  { week: "Week 1", email: 182, chat: 241, phone: 96, resolved: 488 },
  { week: "Week 2", email: 167, chat: 263, phone: 88, resolved: 501 },
  { week: "Week 3", email: 201, chat: 289, phone: 104, resolved: 552 },
  { week: "Week 4", email: 176, chat: 312, phone: 91, resolved: 560 },
  { week: "Week 5", email: 158, chat: 334, phone: 83, resolved: 571 },
  { week: "Week 6", email: 149, chat: 358, phone: 79, resolved: 579 },
  { week: "Week 7", email: 163, chat: 371, phone: 72, resolved: 597 },
  { week: "Week 8", email: 141, chat: 396, phone: 68, resolved: 601 },
];

const chartConfig = {
  email: { label: "Email", colors: { light: ["#1e40af"], dark: ["#93c5fd"] } },
  chat: { label: "Chat", colors: { light: ["#3b82f6"], dark: ["#3b82f6"] } },
  phone: { label: "Phone", colors: { light: ["#93c5fd"], dark: ["#1e40af"] } },
  resolved: { label: "Resolved", colors: { light: ["#0f766e"], dark: ["#2dd4bf"] } },
} satisfies ChartConfig;

export function ExampleStackedComboChart() {
  return (
    <ComboChart
      data={data}
      config={chartConfig}
      xDataKey="week"
      stackType="stacked"
      className="h-full w-full p-4"
    >
      <ComboChart.Grid />
      <ComboChart.XAxis tickFormatter={(value) => value.replace("Week ", "W")} />
      <ComboChart.YAxis />
      <ComboChart.Legend />
      <ComboChart.Tooltip />
      <ComboChart.Bar dataKey="email" />
      <ComboChart.Bar dataKey="chat" />
      <ComboChart.Bar dataKey="phone" />
      <ComboChart.Line dataKey="resolved" strokeVariant="dashed" curveType="linear">
        <ComboChart.Dot variant="colored-border" />
      </ComboChart.Line>
    </ComboChart>
  );
}

```

`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 [#brush]

### ComboChart.Brush

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: Daily rainfall and average temperature over six weeks
const data = Array.from({ length: 42 }, (_, index) => {
  const day = new Date(Date.UTC(2026, 3, 1 + index));
  const rain = Math.sin(index * 0.9) * 6 + Math.cos(index * 0.37) * 5 + 4;
  return {
    date: day.toISOString().slice(0, 10),
    rainfall: Math.max(0, Math.round(rain * 10) / 10),
    temperature: Math.round((14 + index * 0.18 + Math.sin(index * 0.45) * 2.4) * 10) / 10,
  };
});

const chartConfig = {
  rainfall: { label: "Rainfall", colors: { light: ["#0284c7"], dark: ["#38bdf8"] } },
  temperature: { label: "Avg. temperature", colors: { light: ["#dc2626"], dark: ["#f87171"] } },
} satisfies ChartConfig;

const shortDate = (value: string) =>
  new Date(`${value}T00:00:00Z`).toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    timeZone: "UTC",
  });

export function ExampleBrushComboChart() {
  return (
    <ComboChart data={data} config={chartConfig} xDataKey="date" className="h-full w-full p-4">
      <ComboChart.Grid />
      <ComboChart.XAxis tickFormatter={shortDate} />
      <ComboChart.YAxis yAxisId="left" tickFormatter={(value) => `${value} mm`} />
      <ComboChart.YAxis yAxisId="right" tickFormatter={(value) => `${value}°`} />
      <ComboChart.Brush formatLabel={shortDate} />
      <ComboChart.Legend />
      <ComboChart.Tooltip
        labelFormatter={shortDate}
        valueFormatter={(value, key) => (key === "rainfall" ? `${value} mm` : `${value} °C`)}
      />
      <ComboChart.Bar dataKey="rainfall" variant="gradient" />
      <ComboChart.Line dataKey="temperature" yAxisId="right" />
    </ComboChart>
  );
}

```

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 [#reference-lines-and-comparison]

### ReferenceLine and compareDataKey

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: Monthly revenue against last year, with a target and a sale period
const data = [
  { month: "Jan", revenue: 18400, lastYear: 16100, conversion: 2.1, lastYearConversion: 1.9 },
  { month: "Feb", revenue: 21250, lastYear: 17800, conversion: 2.4, lastYearConversion: 2.0 },
  { month: "Mar", revenue: 19870, lastYear: 19200, conversion: 2.2, lastYearConversion: 2.2 },
  { month: "Apr", revenue: 24630, lastYear: 20450, conversion: 2.7, lastYearConversion: 2.3 },
  { month: "May", revenue: 27110, lastYear: 22900, conversion: 2.9, lastYearConversion: 2.5 },
  { month: "Jun", revenue: 25480, lastYear: 24100, conversion: 2.6, lastYearConversion: 2.6 },
  { month: "Jul", revenue: 29960, lastYear: 23700, conversion: 3.1, lastYearConversion: 2.4 },
  { month: "Aug", revenue: 31420, lastYear: 26300, conversion: 3.3, lastYearConversion: 2.7 },
];

const chartConfig = {
  revenue: { label: "Revenue", colors: { light: ["#2563eb"], dark: ["#3b82f6"] } },
  lastYear: { label: "Last year" },
  conversion: { label: "Conversion rate", colors: { light: ["#ea580c"], dark: ["#f97316"] } },
  lastYearConversion: { label: "Last year" },
} satisfies ChartConfig;

export function ExampleReferenceLinesComboChart() {
  return (
    <ComboChart data={data} config={chartConfig} xDataKey="month" className="h-full w-full p-4">
      <ComboChart.Grid />
      <ComboChart.XAxis />
      <ComboChart.YAxis yAxisId="left" tickFormatter={(value) => `$${value / 1000}k`} />
      <ComboChart.YAxis yAxisId="right" tickFormatter={(value) => `${value}%`} />
      <ComboChart.Legend />
      <ComboChart.Tooltip
        valueFormatter={(value, key) =>
          key.toLowerCase().includes("conversion") ? `${value.toFixed(1)}%` : `$${value.toLocaleString()}`
        }
      />
      <ComboChart.ReferenceArea x1="Jul" x2="Aug" label="Summer sale" /> {/* [!code highlight] */}
      <ComboChart.ReferenceLine y={28000} label="Target $28k" /> {/* [!code highlight] */}
      <ComboChart.Bar dataKey="revenue" compareDataKey="lastYear" /> {/* [!code highlight] */}
      <ComboChart.Line dataKey="conversion" yAxisId="right" compareDataKey="lastYearConversion"> {/* [!code highlight] */}
        <ComboChart.Dot variant="border" />
      </ComboChart.Line>
    </ComboChart>
  );
}

```

`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](/docs/charts/ui/reference-lines) and [Period Comparison](/docs/charts/ui/comparison).

### Synced Crosshair [#synced-crosshair]

### syncId=&#x22;share-day&#x22;

```tsx
"use client";

import { CandlestickChart } from "honestui/charts";
import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: A share price and its trading activity on the same days
const data = (() => {
  const rows: {
    date: string;
    open: number;
    close: number;
    high: number;
    low: number;
    trades: number;
    average: number;
  }[] = [];
  let close = 182.4;
  const day = new Date(Date.UTC(2026, 8, 1));
  while (rows.length < 24) {
    const weekday = day.getUTCDay();
    if (weekday !== 0 && weekday !== 6) {
      const i = rows.length;
      const open = Math.round((close + Math.sin(i * 2.3) * 0.9) * 100) / 100;
      close = Math.round((open + Math.sin(i * 0.55) * 2.6 + Math.cos(i * 1.7) * 1.4) * 100) / 100;
      const trades = Math.round(4200 + Math.abs(close - open) * 1600 + Math.abs(Math.sin(i * 0.9)) * 1800);
      rows.push({
        date: day.toISOString().slice(0, 10),
        open,
        close,
        high: Math.round((Math.max(open, close) + 0.6 + Math.abs(Math.sin(i * 3.1)) * 1.8) * 100) / 100,
        low: Math.round((Math.min(open, close) - 0.6 - Math.abs(Math.cos(i * 2.7)) * 1.8) * 100) / 100,
        trades,
        average: 0,
      });
    }
    day.setUTCDate(day.getUTCDate() + 1);
  }
  rows.forEach((row, i) => {
    const window = rows.slice(Math.max(0, i - 4), i + 1);
    row.average = Math.round(window.reduce((sum, r) => sum + r.trades, 0) / window.length);
  });
  return rows;
})();

const priceConfig = {
  up: { label: "Up", colors: { light: ["#16a34a"], dark: ["#22c55e"] } },
  down: { label: "Down", colors: { light: ["#dc2626"], dark: ["#ef4444"] } },
} satisfies ChartConfig;

const activityConfig = {
  trades: { label: "Trades", colors: { light: ["#94a3b8"], dark: ["#475569"] } },
  average: { label: "5-day average", colors: { light: ["#2563eb"], dark: ["#60a5fa"] } },
} satisfies ChartConfig;

const shortDate = (value: string) =>
  new Date(`${value}T00:00:00Z`).toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    timeZone: "UTC",
  });

export function ExampleSyncedCrosshairComboChart() {
  return (
    <div className="grid h-full w-full grid-rows-[3fr_2fr] gap-2 p-4">
      <CandlestickChart data={data} config={priceConfig} xDataKey="date" syncId="share-day" className="min-h-0"> {/* [!code highlight] */}
        <CandlestickChart.Grid />
        <CandlestickChart.YAxis position="left" tickFormatter={(value) => `$${value.toFixed(0)}`} />
        <CandlestickChart.Tooltip crosshair={false} labelFormatter={shortDate} valueFormatter={(value) => `$${value.toFixed(2)}`} />
        <CandlestickChart.Candles />
      </CandlestickChart>
      <ComboChart data={data} config={activityConfig} xDataKey="date" syncId="share-day" className="min-h-0"> {/* [!code highlight] */}
        <ComboChart.Grid />
        <ComboChart.XAxis tickFormatter={shortDate} />
        <ComboChart.YAxis tickFormatter={(value) => `${(value / 1000).toFixed(0)}k`} />
        <ComboChart.Tooltip labelFormatter={shortDate} />
        <ComboChart.Bar dataKey="trades" />
        <ComboChart.Line dataKey="average" />
      </ComboChart>
    </div>
  );
}

```

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](/docs/charts/ui/sync) and [Brush and Zoom](/docs/charts/ui/brush).

### Loading State [#loading-state]

### isLoading='true'

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

const chartConfig = {
  revenue: { label: "Revenue", colors: { light: ["#2563eb"], dark: ["#3b82f6"] } },
  conversion: { label: "Conversion rate", colors: { light: ["#ea580c"], dark: ["#f97316"] } },
} satisfies ChartConfig;

export function ExampleLoadingComboChart() {
  return (
    <ComboChart data={[]} config={chartConfig} isLoading className="h-full w-full p-4">
      <ComboChart.Grid />
      <ComboChart.XAxis />
      <ComboChart.Bar dataKey="revenue" />
      <ComboChart.Line dataKey="conversion" />
    </ComboChart>
  );
}

```

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

## API Reference [#api-reference]

<ApiHeading>
  ComboChart
</ApiHeading>


  ### `data`

type: `TData[]`

One row per category.

  ### `config`

type: `ChartConfig`

Labels and theme colors for every bar and line key. See [Chart Config](/docs/charts/chart-config).

  ### `xDataKey`

type: `keyof TData & string`

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

  ### `stackType`

type: `&#x22;default&#x22; | &#x22;stacked&#x22;` · default: `&#x22;default&#x22;`

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

  ### `barRadius`

type: `number` · default: `2`

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

  ### `curveType`

type: `&#x22;linear&#x22; | &#x22;smooth&#x22; | &#x22;step&#x22;` · default: `&#x22;smooth&#x22;`

Default curve for every line.

  ### `barGap`

type: `number`

Gap between grouped bars, in pixels.

  ### `barCategoryGap`

type: `number`

Gap between categories, in pixels.

  ### `animation`

type: `boolean` · default: `true`

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

  ### `defaultSelectedDataKey`

type: `string | null` · default: `null`

The series selected on first render.

  ### `onSelectionChange`



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

  ### `isLoading`

type: `boolean` · default: `false`

Shows the loading silhouette and label.

  ### `syncId`

type: `string`

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

  ### `ariaLabel`

type: `string`

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

  ### `chartOptions`



">
    Escape hatch merged over the generated ECharts option.


<ApiHeading>
  Bar
</ApiHeading>


  ### `dataKey`

type: `string`

The series field and config key.

  ### `variant`

type: `&#x22;default&#x22; | &#x22;gradient&#x22; | &#x22;hatched&#x22; | &#x22;duotone&#x22;` · default: `&#x22;default&#x22;`

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

  ### `radius`

type: `number`

Overrides `barRadius` for this series.

  ### `yAxisId`

type: `&#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;left&#x22;`

The value axis the bar is measured against.

  ### `isClickable`

type: `boolean` · default: `false`

Lets a click select the series.

  ### `enableHoverHighlight`

type: `boolean` · default: `false`

Dims the other bars while one is hovered.

  ### `compareDataKey`

type: `string`

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.


<ApiHeading>
  Line
</ApiHeading>


  ### `dataKey`

type: `string`

The series field and config key.

  ### `yAxisId`

type: `&#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;left&#x22;`

The value axis the line is measured against.

  ### `curveType`

type: `&#x22;linear&#x22; | &#x22;smooth&#x22; | &#x22;step&#x22;`

Overrides the root `curveType`.

  ### `strokeVariant`

type: `&#x22;solid&#x22; | &#x22;dashed&#x22;` · default: `&#x22;solid&#x22;`

Dashes suit targets and forecasts.

  ### `strokeWidth`

type: `number` · default: `1.5`

Line width in pixels.

  ### `connectNulls`

type: `boolean` · default: `false`

Bridges missing values instead of leaving a gap.

  ### `compareDataKey`

type: `string`

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

  ### `isClickable`

type: `boolean` · default: `false`

Lets a click select the series.

  ### `children`

type: `ReactNode`

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


<ApiHeading>
  YAxis
</ApiHeading>


  ### `yAxisId`

type: `&#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;left&#x22;`

Which side this axis describes. Add one per side.

  ### `tickFormatter`



string">
    Formats tick labels.

  ### `label`

type: `string`

Axis title.

  ### `min`

type: `number`

Fixes the lower bound.

  ### `max`

type: `number`

Fixes the upper bound.

  ### `hideDots`

type: `boolean` · default: `false`

Hides the tick dots.


<ApiHeading>
  XAxis
</ApiHeading>


  ### `dataKey`

type: `string`

The category field, if not set on the root.

  ### `tickFormatter`



string">
    Formats category labels.

  ### `label`

type: `string`

Axis title.

  ### `hideDots`

type: `boolean` · default: `false`

Hides the tick dots.


<ApiHeading>
  Tooltip
</ApiHeading>


  ### `variant`

type: `&#x22;default&#x22; | &#x22;frosted-glass&#x22;` · default: `&#x22;default&#x22;`

Tooltip surface.

  ### `roundness`

type: `&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;` · default: `&#x22;lg&#x22;`

Tooltip corner radius.

  ### `position`

type: `&#x22;fixed&#x22; | &#x22;variable&#x22;` · default: `&#x22;variable&#x22;`

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

  ### `cursor`

type: `boolean` · default: `true`

Draws the dashed line at the hovered category.

  ### `valueFormatter`



string">
    Formats each row. Receives the series key.

  ### `labelFormatter`



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

  ### `defaultIndex`

type: `number`

Opens the tooltip at a category after mount.


<ApiHeading>
  Legend
</ApiHeading>


  ### `variant`

type: `LegendVariant` · default: `&#x22;rounded-square&#x22;`

Indicator shape, shared with the other charts.

  ### `align`

type: `&#x22;left&#x22; | &#x22;center&#x22; | &#x22;right&#x22;` · default: `&#x22;right&#x22;`

Horizontal alignment.

  ### `verticalAlign`

type: `&#x22;top&#x22; | &#x22;middle&#x22; | &#x22;bottom&#x22;` · default: `&#x22;top&#x22;`

Vertical placement.

  ### `isClickable`

type: `boolean` · default: `false`

Lets a legend item select its series.


<ApiHeading>
  Brush
</ApiHeading>


  ### `height`

type: `number` · default: `56`

Height of the preview strip in pixels.

  ### `formatLabel`



string">
    Formats the range labels shown while the brush is hovered.

  ### `onChange`



void">
    Fires when the selected range changes.


<ApiHeading>
  Zoom, ReferenceLine, ReferenceArea, ReferenceDot
</ApiHeading>

`ComboChart.Zoom` takes the props listed in [Brush and Zoom](/docs/charts/ui/brush). The reference parts take the props listed in [Reference Lines](/docs/charts/ui/reference-lines); a `y` value is read on the left value axis.
