# Composed Chart

Animated bar and line series combined in one Cartesian chart.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).





<ComponentPreview base="chartgpu" title="Basic Chart" name="composed-chart-demo">
  <ChartcnExampleComposedChart />
</ComponentPreview>

## Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @chartcn/chartgpu/composed-chart
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      npm install @chartgpu/chartgpu
      ```

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource src="registry/bases/chartgpu/ui/chart.tsx" title="components/chart/chart.tsx" />

      <ComponentSource src="registry/bases/chartgpu/ui/tooltip.ts" title="components/chart/tooltip.ts" />

      <ComponentSource src="registry/bases/chartgpu/components/cartesian-chart/brush.tsx" title="components/chart/cartesian-chart/brush.tsx" />

      <ComponentSource src="registry/bases/chartgpu/components/cartesian-chart/types.ts" title="components/chart/cartesian-chart/types.ts" />

      <ComponentSource src="registry/bases/chartgpu/components/cartesian-chart/cartesian.ts" title="components/chart/cartesian-chart/cartesian.ts" />

      <ComponentSource src="registry/bases/chartgpu/components/cartesian-chart/cartesian-chart.tsx" title="components/chart/cartesian-chart/cartesian-chart.tsx" />

      <ComponentSource src="registry/bases/chartgpu/components/composed-chart/composed-chart.tsx" title="components/chart/composed-chart.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

## Usage [#usage]

```tsx
import {
  ChartcnComposedChart,
  type ChartConfig,
} from "@/components/chart/composed-chart";
```

```tsx
<ChartcnComposedChart config={chartConfig} data={data} xDataKey="month">
  <ChartcnComposedChart.Grid />
  <ChartcnComposedChart.XAxis dataKey="month" />
  <ChartcnComposedChart.Brush />
  <ChartcnComposedChart.Legend />
  <ChartcnComposedChart.Tooltip />
  <ChartcnComposedChart.Bar dataKey="revenue" />
  <ChartcnComposedChart.Line dataKey="profit" strokeWidth={2.5} />
</ChartcnComposedChart>
```

## Examples [#examples]

### Loading state [#loading-state]

<ComponentPreview base="chartgpu" title="isLoading='true'" name="loading-state-composed-chart-demo">
  <LoadingComposedChart />
</ComponentPreview>

## API Reference [#api-reference]

### ChartcnComposedChart [#chartcncomposedchart]

| Prop        | Type                                                | Default                                 |
| ----------- | --------------------------------------------------- | --------------------------------------- |
| `data`      | `Data[]`                                            | `required`                              |
| `config`    | `ChartConfig`                                       | `required`                              |
| `xDataKey`  | `string`                                            | -                                       |
| `stackType` | `"default" \| "stacked" \| "expanded" \| "percent"` | `"default"`                             |
| `animation` | `boolean \| AnimationConfig`                        | `{ duration: 650, easing: "cubicOut" }` |
| `isLoading` | `boolean`                                           | `false`                                 |

### Bar [#bar]

| Prop       | Type               | Default     |
| ---------- | ------------------ | ----------- |
| `dataKey`  | `string`           | `required`  |
| `radius`   | `number`           | `4`         |
| `barWidth` | `number \| string` | -           |
| `stackId`  | `string`           | `"chartcn"` |

### Line [#line]

| Prop           | Type                                                  | Default    |
| -------------- | ----------------------------------------------------- | ---------- |
| `dataKey`      | `string`                                              | `required` |
| `strokeWidth`  | `number`                                              | `2.25`     |
| `opacity`      | `number`                                              | `1`        |
| `curveType`    | `"linear" \| "step" \| "step-before" \| "step-after"` | -          |
| `connectNulls` | `boolean`                                             | `false`    |

### Shared parts [#shared-parts]

`Grid`, `XAxis`, `YAxis`, `Brush`, `Legend`, and `Tooltip` accept the concrete props documented by the [Line Chart](/docs/components/chartgpu/line-chart#shared-parts).
