# Composed Chart

Bars and lines together, such as a count beside a rate.

Page: https://sui.draco.dev/docs/charts/composed-chart

### Example: composed-chart-demo

```tsx
"use client";
import {
  ComposedChart,
  chartLabelsZhCN,
  numberFormatter,
} from "@workspace/ui/charts/composed-chart";
import type { ExampleProps } from "../types";

const orders = [
  { month: "Jan", orders: 420, conversion: 0.031 },
  { month: "Feb", orders: 510, conversion: 0.034 },
  { month: "Mar", orders: 480, conversion: 0.029 },
  { month: "Apr", orders: 620, conversion: 0.041 },
  { month: "May", orders: 700, conversion: 0.044 },
  { month: "Jun", orders: 660, conversion: 0.039 },
];

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  return (
    <ComposedChart
      data={orders}
      config={{
        orders: { label: chinese ? "订单" : "Orders", color: "var(--chart-1)" },
        conversion: {
          label: chinese ? "转化率" : "Conversion",
          color: "var(--chart-4)",
        },
      }}
      index="month"
      bars={["orders"]}
      lines={["conversion"]}
      lineAxis
      lineValueFormatter={numberFormatter(
        { style: "percent", maximumFractionDigits: 1 },
        locale,
      )}
      showLegend
      labels={chinese ? chartLabelsZhCN : undefined}
    />
  );
}
```

## Installation

```bash
npx shadcn@latest add @sui/composed-chart
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

## Usage

```tsx
import { ComposedChart } from "@workspace/ui/charts/composed-chart";

<ComposedChart data={data} config={config} index="month" bars={["orders"]} lines={["conversion"]} lineAxis />;
```

## Customize

The wrapper covers common cases. For more control, pass Recharts elements as `children`, or compose your own chart with the [Chart](/docs/charts/chart) primitives.

## API reference

| Prop | Type | Default / behavior |
| --- | --- | --- |
| `bars` | `readonly string[]` | Required. Series drawn as bars. |
| `lines` | `readonly string[]` | Required. Series drawn as lines. |
| `lineAxis` | `boolean` | `false`. Plots lines on a second y axis. |
| `lineValueFormatter` | `(value: number) => string` | `valueFormatter`. |
| `curve` | `"linear" \| "natural" \| "monotone" \| "step"` | `"monotone"`. |
| `index` | `string` | Required. The category-axis key. |
| `showGrid` / `showXAxis` / `showYAxis` | `boolean` | Grid and x axis on; y axis varies by chart. |
| `dir` | `"ltr" \| "rtl"` | `"ltr"`. Mirrors the axes. |
| `data` | `readonly Record<string, unknown>[]` | Required rows. |
| `config` | `ChartConfig` | Required. Labels, colors and icons by key; series without a color use `--chart-1` to `--chart-5`. |
| `valueFormatter` | `(value: number) => string` | `toLocaleString`. Formats axes, tooltip and the screen-reader table; build one with `numberFormatter`. |
| `showLegend` | `boolean` | `false`. Legend buttons show and hide series. |
| `showTooltip` | `boolean` | `true`. |
| `loading` | `boolean` | `false`. Shows a skeleton. |
| `labels` | `Partial<ChartLabels>` | English labels; pass `chartLabelsZhCN` for Chinese. |
| `aria-label` | `string` | Names the figure and captions its data table. |
| `className` | `string` | Sizes the chart; defaults to a 16:9 box. |
| `children` | `ReactNode` | Extra Recharts elements, such as `ReferenceLine`. |

The module also exports `ComposedChartProps`, `numberFormatter`, and the label presets `chartLabels` and `chartLabelsZhCN`. Screen readers get a hidden data table while the drawing itself is hidden from assistive technology, and animation is off when reduced motion is requested.
