# Area Chart

Ten area charts for showing how values change over time, from a single smooth area to stacked, gradient, step, range and sparkline areas.

Area Chart is an open-source chart from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

Source: https://suiss.app/ui/docs/charts/area-chart

Area charts show how a value moves over time and how big it is at each point. Use the default for one series, stack areas to show a total and its parts, expand them to 100% to compare shares, and switch to linear or step lines when the readings should not look smoothed. The range variant shades a low-to-high band, and the sparkline fits a tiny trend beside a value.

Each chart is built on the [Chart](https://suiss.app/ui/docs/components/chart) and [Card](https://suiss.app/ui/docs/components/card) components.

Every variant below is its own registry item, so you can add only the ones you need. Each one renders the same design on React, React Native, SwiftUI and Jetpack Compose.


## Area Chart Default

A single filled area with a smooth curve showing one series across six months.

Source: https://suiss.app/ui/docs/charts/area-chart#default

**React**

**Example**

```tsx title="components/charts/area-chart-default.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Area chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="natural"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

The baseline area chart: one series as a smooth, lightly filled curve with a month axis and a tooltip, and no value axis. Start here when you only need the shape of a trend and want to build up from the simplest version.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`, where colors follow light and dark mode. Change the curve with the `type` prop on the area, for example to straight lines or steps. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-default
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-default
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-default.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Area chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="natural"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartDefault } from "@/components/charts/area-chart-default"
```

```tsx
<AreaChartDefault />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Area chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Area chart"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartDefault.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
]

public struct AreaChartDefault: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Area chart", description: "Desktop visitors · January to June")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                AreaMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.catmullRom)
                  .foregroundStyle(chartConfig.color("desktop").opacity(0.18))
                LineMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.catmullRom)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(chartConfig.color("desktop"))
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
              if let selection {
                PointMark(x: .value("Month", selection), y: .value("Desktop", chartData[selection].desktop))
                  .symbolSize(64)
                  .foregroundStyle(chartConfig.color("desktop"))
              }
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Area chart",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload, indicator: .line)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartDefault.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator

private class AreaDefaultRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaDefaultRow("January", 186.0, 80.0),
    AreaDefaultRow("February", 305.0, 200.0),
    AreaDefaultRow("March", 237.0, 120.0),
    AreaDefaultRow("April", 173.0, 190.0),
    AreaDefaultRow("May", 209.0, 130.0),
    AreaDefaultRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
)

@Composable
fun AreaChartDefault(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Area chart", description = "Desktop visitors · January to June")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 12.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Area chart",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip { ChartTooltipContent(indicator = ChartTooltipIndicator.Line) }
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Natural,
                        strokeWidth = 2.dp,
                        fill = ChartFill.Solid(alpha = 0.18f),
                    )
                }
            }
        }
    }
}
```

The baseline area chart inside a `Card`: one series drawn as a natural curve with a light fill, a dashed horizontal grid, a month axis and a tooltip with a line indicator. There is no value axis. Press and drag across the plot to move the tooltip between months.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Rename the series in `chartConfig` to set its label and color. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-default
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-default --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-default
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-default --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-default.tsx`:

- `uniwind/components/charts/area-chart-default.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-default.tsx`:

```tsx title="nativewind/components/charts/area-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Area chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Area chart"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-default.tsx`:

```tsx title="stylesheet/components/charts/area-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Area chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Area chart"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartDefault.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartDefault.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartDefault } from "@/components/charts/area-chart-default"
```

```tsx
<AreaChartDefault />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaExample: View {
  var body: some View {
    AreaChartDefault()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartDefault

@Composable
fun AreaExample() {
    AreaChartDefault()
}
```



## Area Chart Axes

A gradient area with visible dots and a value axis on the right edge of the plot.

Source: https://suiss.app/ui/docs/charts/area-chart#axes

**React**

**Example**

```tsx title="components/charts/area-chart-axes.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartAxes() {
  const id = React.useId()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With axes</CardTitle>
        <CardDescription>A value axis on the right</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <defs>
              <linearGradient id={`${id}-desktop`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              tickCount={4}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="desktop"
              type="monotone"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill={`url(#${id}-desktop)`}
              dot={{ r: 3, fill: "var(--color-desktop)", strokeWidth: 0 }}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A single series drawn as a smooth area with a soft gradient fill, a dot at every value and a value axis on the right. Use it when readers need to read exact values off the chart, not just see the trend.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`. Set `orientation` on the value axis to move it to the left and `tickCount` to change how many values it shows. Each copy gets its own gradient, so several can share a page. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-axes
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-axes
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-axes.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartAxes() {
  const id = React.useId()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With axes</CardTitle>
        <CardDescription>A value axis on the right</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <defs>
              <linearGradient id={`${id}-desktop`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              tickCount={4}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="desktop"
              type="monotone"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill={`url(#${id}-desktop)`}
              dot={{ r: 3, fill: "var(--color-desktop)", strokeWidth: 0 }}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartAxes } from "@/components/charts/area-chart-axes"
```

```tsx
<AreaChartAxes />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-axes.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartAxes() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With axes</CardTitle>
        <CardDescription>A value axis on the right</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With axes"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={4}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="desktop"
              type="monotone"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.38 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              dot={{ r: 3 }}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartAxes.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
]

public struct AreaChartAxes: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    let color = chartConfig.color("desktop")
    Card(.filled, size: .sm) {
      CardHeader("With axes", description: "A value axis on the right")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                AreaMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.monotone)
                  .foregroundStyle(LinearGradient(colors: [color.opacity(0.38), color.opacity(0.02)], startPoint: .top, endPoint: .bottom))
                LineMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.monotone)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(color)
                PointMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .symbolSize(selection == index ? 64 : 36)
                  .foregroundStyle(color)
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.y(count: 4) { $0.formatted() } }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "With axes",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartAxes.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartAxisOrientation
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartDot
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent

private class AreaAxesRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaAxesRow("January", 186.0, 80.0),
    AreaAxesRow("February", 305.0, 200.0),
    AreaAxesRow("March", 237.0, 120.0),
    AreaAxesRow("April", 173.0, 190.0),
    AreaAxesRow("May", 209.0, 130.0),
    AreaAxesRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
)

@Composable
fun AreaChartAxes(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("With axes", description = "A value axis on the right")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "With axes",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    YAxis(orientation = ChartAxisOrientation.Right, tickMargin = 6.dp, tickCount = 4)
                    ChartTooltip { ChartTooltipContent() }
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Monotone,
                        strokeWidth = 2.dp,
                        fill = ChartFill.VerticalGradient(topAlpha = 0.38f, bottomAlpha = 0.02f),
                        dot = ChartDot(3.dp),
                    )
                }
            }
        }
    }
}
```

One series drawn as a monotone curve with a fill that fades from top to bottom, a dot on every month, a month axis below and a four-tick value axis on the right. The tooltip follows your finger across the plot.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Set the label and color in `chartConfig`, and adjust `tickCount` on the `YAxis` to change how many values it shows. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-axes
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-axes
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-axes
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-axes --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-axes
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-axes --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-axes.tsx`:

- `uniwind/components/charts/area-chart-axes.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-axes.tsx`:

```tsx title="nativewind/components/charts/area-chart-axes.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartAxes() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With axes</CardTitle>
        <CardDescription>A value axis on the right</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With axes"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={4}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="desktop"
              type="monotone"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.38 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              dot={{ r: 3 }}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-axes.tsx`:

```tsx title="stylesheet/components/charts/area-chart-axes.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartAxes() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>With axes</CardTitle>
        <CardDescription>A value axis on the right</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="With axes"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={4}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="desktop"
              type="monotone"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.38 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              dot={{ r: 3 }}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartAxes.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartAxes.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartAxes } from "@/components/charts/area-chart-axes"
```

```tsx
<AreaChartAxes />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaAxesExample: View {
  var body: some View {
    AreaChartAxes()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartAxes

@Composable
fun AreaAxesExample() {
    AreaChartAxes()
}
```



## Area Chart Gradient

Two overlapping areas whose fills fade out toward the bottom using SVG linear gradients.

Source: https://suiss.app/ui/docs/charts/area-chart#gradient

**React**

**Example**

```tsx title="components/charts/area-chart-gradient.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartGradient() {
  const id = React.useId()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Gradient</CardTitle>
        <CardDescription>The fill fades out toward the bottom</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <defs>
              <linearGradient id={`${id}-desktop`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.02}
                />
              </linearGradient>
              <linearGradient id={`${id}-mobile`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-mobile)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-mobile)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stroke="var(--color-mobile)"
              strokeWidth={2}
              fill={`url(#${id}-mobile)`}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill={`url(#${id}-desktop)`}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two overlapping series whose fills fade to transparent toward the baseline, so the lower series stays visible through the upper one. Reach for it over the flat-filled default when you compare two series that cross each other.

Replace `chartData` and rename the two series keys in the data, the areas and `chartConfig`. Each series needs its own gradient in the `defs` block, and the top stop's `stopOpacity` sets the strength of the fill. Areas are drawn in source order, so the last `Area` sits on top. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-gradient
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-gradient
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-gradient.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartGradient() {
  const id = React.useId()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Gradient</CardTitle>
        <CardDescription>The fill fades out toward the bottom</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <defs>
              <linearGradient id={`${id}-desktop`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-desktop)"
                  stopOpacity={0.02}
                />
              </linearGradient>
              <linearGradient id={`${id}-mobile`} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-mobile)"
                  stopOpacity={0.38}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-mobile)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stroke="var(--color-mobile)"
              strokeWidth={2}
              fill={`url(#${id}-mobile)`}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill={`url(#${id}-desktop)`}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartGradient } from "@/components/charts/area-chart-gradient"
```

```tsx
<AreaChartGradient />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-gradient.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

const fade = {
  stops: [
    { offset: 0, opacity: 0.38 },
    { offset: 1, opacity: 0.02 },
  ],
}

export function AreaChartGradient() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Gradient</CardTitle>
        <CardDescription>The fill fades out toward the bottom</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Gradient"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area dataKey="mobile" type="natural" strokeWidth={2} fill={fade} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fill={fade}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartGradient.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
  "mobile": .init("Mobile", color: EsuissColor.chart2),
]

private func value(_ key: String, _ index: Int) -> Double {
  key == "desktop" ? chartData[index].desktop : chartData[index].mobile
}

public struct AreaChartGradient: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Gradient", description: "The fill fades out toward the bottom")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(["mobile", "desktop"], id: \.self) { key in
                let color = chartConfig.color(key)
                ForEach(chartData.indices, id: \.self) { index in
                  AreaMark(x: .value("Month", index), y: .value("Visitors", value(key, index)), series: .value("Series", key))
                    .interpolationMethod(.catmullRom)
                    .foregroundStyle(LinearGradient(colors: [color.opacity(0.38), color.opacity(0.02)], startPoint: .top, endPoint: .bottom))
                  LineMark(x: .value("Month", index), y: .value("Visitors", value(key, index)), series: .value("Series", key))
                    .interpolationMethod(.catmullRom)
                    .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                    .foregroundStyle(color)
                }
                .chartReveal(progress, x: 0...(chartData.count - 1))
                if let selection {
                  PointMark(x: .value("Month", selection), y: .value("Visitors", value(key, selection)))
                    .symbolSize(64)
                    .foregroundStyle(color)
                }
              }
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Gradient",
              items: { index in ["mobile", "desktop"].map { ChartTooltipItem($0, value: value($0, index)) } }
            ) { payload in
              ChartTooltipContent(payload)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartGradient.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent

private class AreaGradientRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaGradientRow("January", 186.0, 80.0),
    AreaGradientRow("February", 305.0, 200.0),
    AreaGradientRow("March", 237.0, 120.0),
    AreaGradientRow("April", 173.0, 190.0),
    AreaGradientRow("May", 209.0, 130.0),
    AreaGradientRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
    "mobile" to ChartConfigItem("Mobile") { chart2 },
)

@Composable
fun AreaChartGradient(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Gradient", description = "The fill fades out toward the bottom")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 12.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Gradient",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip { ChartTooltipContent() }
                    Area(
                        "mobile",
                        value = { it.mobile },
                        curve = ChartCurve.Natural,
                        strokeWidth = 2.dp,
                        fill = ChartFill.VerticalGradient(topAlpha = 0.38f, bottomAlpha = 0.02f),
                    )
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Natural,
                        strokeWidth = 2.dp,
                        fill = ChartFill.VerticalGradient(topAlpha = 0.38f, bottomAlpha = 0.02f),
                    )
                }
            }
        }
    }
}
```

Two series, desktop and mobile, drawn as natural curves on the same axis. Both use a shared gradient fill that fades out toward the baseline, so the overlap stays readable. A month axis, a dashed grid and a tooltip listing both values complete the chart.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Add or rename series in `chartConfig`, and change the `fade` stops to make the gradient stronger or lighter. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-gradient
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-gradient
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-gradient
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-gradient --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-gradient
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-gradient --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-gradient.tsx`:

- `uniwind/components/charts/area-chart-gradient.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-gradient.tsx`:

```tsx title="nativewind/components/charts/area-chart-gradient.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

const fade = {
  stops: [
    { offset: 0, opacity: 0.38 },
    { offset: 1, opacity: 0.02 },
  ],
}

export function AreaChartGradient() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Gradient</CardTitle>
        <CardDescription>The fill fades out toward the bottom</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Gradient"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area dataKey="mobile" type="natural" strokeWidth={2} fill={fade} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fill={fade}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-gradient.tsx`:

```tsx title="stylesheet/components/charts/area-chart-gradient.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

const fade = {
  stops: [
    { offset: 0, opacity: 0.38 },
    { offset: 1, opacity: 0.02 },
  ],
}

export function AreaChartGradient() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Gradient</CardTitle>
        <CardDescription>The fill fades out toward the bottom</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Gradient"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Area dataKey="mobile" type="natural" strokeWidth={2} fill={fade} />
            <Area
              dataKey="desktop"
              type="natural"
              strokeWidth={2}
              fill={fade}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartGradient.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartGradient.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartGradient } from "@/components/charts/area-chart-gradient"
```

```tsx
<AreaChartGradient />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaGradientExample: View {
  var body: some View {
    AreaChartGradient()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartGradient

@Composable
fun AreaGradientExample() {
    AreaChartGradient()
}
```



## Area Chart Interactive

A stock price chart with time-range toggles, a scrubbing cursor that updates the header, and animated transitions between ranges.

Source: https://suiss.app/ui/docs/charts/area-chart#interactive

**React**

**Example**

```tsx title="components/charts/area-chart-interactive.tsx"
"use client"

import * as React from "react"
import {
  Area,
  AreaChart,
  CartesianGrid,
  ReferenceLine,
  useActiveTooltipDataPoints,
  XAxis,
  YAxis,
} from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
} from "@/components/ui/chart"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Range = "1D" | "1W" | "1M" | "3M" | "1Y" | "5Y"

type Point = { index: number; price: number; label: string; tick: string }

const RANGES: Record<
  Range,
  {
    points: number
    seed: number
    volatility: number
    drift: number
    caption: string
  }
> = {
  "1D": {
    points: 78,
    seed: 11,
    volatility: 0.0025,
    drift: 0.46,
    caption: "Today",
  },
  "1W": {
    points: 35,
    seed: 23,
    volatility: 0.004,
    drift: 0.46,
    caption: "Past week",
  },
  "1M": {
    points: 22,
    seed: 37,
    volatility: 0.012,
    drift: 0.53,
    caption: "Past month",
  },
  "3M": {
    points: 64,
    seed: 41,
    volatility: 0.014,
    drift: 0.46,
    caption: "Past 3 months",
  },
  "1Y": {
    points: 52,
    seed: 59,
    volatility: 0.03,
    drift: 0.46,
    caption: "Past year",
  },
  "5Y": {
    points: 60,
    seed: 73,
    volatility: 0.045,
    drift: 0.46,
    caption: "Past 5 years",
  },
}

const LAST_PRICE = 254.32
const END = new Date(2026, 9, 6)
const SAMPLES = 80
const MORPH_DURATION = 520

const priceFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
})
const changeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
  signDisplay: "always",
})
const dayFormat = new Intl.DateTimeFormat("en-US", {
  month: "short",
  day: "numeric",
})
const weekdayFormat = new Intl.DateTimeFormat("en-US", { weekday: "short" })
const monthFormat = new Intl.DateTimeFormat("en-US", { month: "short" })
const monthYearFormat = new Intl.DateTimeFormat("en-US", {
  month: "long",
  year: "numeric",
})

function businessDays(count: number) {
  const days: Date[] = []
  const day = new Date(END)
  while (days.length < count) {
    if (day.getDay() % 6) days.unshift(new Date(day))
    day.setDate(day.getDate() - 1)
  }
  return days
}

function generate(range: Range): Point[] {
  const { points, seed, volatility, drift } = RANGES[range]
  let state = seed
  let value = 100
  const values = Array.from({ length: points }, () => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - drift) * volatility
    return value
  })
  const last = values.at(-1)
  if (last === undefined) return []
  const scale = LAST_PRICE / last
  const days = businessDays(points)
  const week = businessDays(5)

  return values.map((raw, index) => {
    const price = Number((raw * scale).toFixed(2))
    if (range === "1D") {
      const minutes = 570 + index * 5
      const hour = Math.floor(minutes / 60)
      const minute = minutes % 60
      const time = `${hour}:${String(minute).padStart(2, "0")}`
      return {
        index,
        price,
        label: time,
        tick: minute === 0 ? `${hour}:00` : "",
      }
    }
    if (range === "1W") {
      const day = week[Math.floor(index / 7)]
      const weekday = weekdayFormat.format(day)
      return {
        index,
        price,
        label: `${weekday} ${10 + (index % 7)}:00`,
        tick: index % 7 === 0 ? weekday : "",
      }
    }
    if (range === "1M" || range === "3M") {
      const label = dayFormat.format(days[index])
      return { index, price, label, tick: label }
    }
    if (range === "1Y") {
      const day = new Date(END)
      day.setDate(day.getDate() - (points - 1 - index) * 7)
      return {
        index,
        price,
        label: `${dayFormat.format(day)}, ${day.getFullYear()}`,
        tick: monthFormat.format(day),
      }
    }
    const month = new Date(
      END.getFullYear(),
      END.getMonth() - (points - 1 - index),
      1
    )
    return {
      index,
      price,
      label: monthYearFormat.format(month),
      tick: String(month.getFullYear()),
    }
  })
}

function resample(source: Point[]) {
  const samples: Point[] = []
  let previous = -1
  for (let index = 0; index < SAMPLES; index++) {
    const position = (index * (source.length - 1)) / (SAMPLES - 1)
    const from = Math.floor(position)
    const to = Math.min(source.length - 1, from + 1)
    const nearest = Math.round(position)
    const start = source[from]
    const end = source[to]
    const closest = source[nearest]
    if (!start || !end || !closest) return samples
    const price = start.price + (end.price - start.price) * (position - from)
    samples.push({
      index,
      price: Number(price.toFixed(2)),
      label: closest.label,
      tick: nearest !== previous ? closest.tick : "",
    })
    previous = nearest
  }
  return samples
}

function tickIndexes(points: Point[], max: number) {
  const ticks = points
    .filter(
      (point, index) => point.tick && point.tick !== points[index - 1]?.tick
    )
    .map((point) => point.index)
  if (ticks.length <= max) return ticks
  const step = Math.ceil(ticks.length / max)
  return ticks.filter((_, index) => index % step === 0)
}

function useMorph(target: number[]) {
  const [values, setValues] = React.useState(target)
  const valuesRef = React.useRef(values)

  React.useEffect(() => {
    const from = valuesRef.current
    if (
      target.length === from.length &&
      target.every((value, index) => value === from[index])
    )
      return
    const reduced = window.matchMedia(
      "(prefers-reduced-motion: reduce)"
    ).matches
    const start = performance.now()
    let frame = 0
    const step = () => {
      const progress = reduced
        ? 1
        : Math.min(1, (performance.now() - start) / MORPH_DURATION)
      const eased = 1 - (1 - progress) ** 3
      const next =
        progress < 1
          ? target.map((value, index) => {
              const origin = from[index] ?? value
              return origin + (value - origin) * eased
            })
          : target
      valuesRef.current = next
      setValues(next)
      if (progress < 1) frame = requestAnimationFrame(step)
    }
    frame = requestAnimationFrame(step)
    return () => cancelAnimationFrame(frame)
  }, [target])

  return values
}

function ActivePoint({
  onChange,
}: {
  onChange: (index: number | null) => void
}) {
  const points = useActiveTooltipDataPoints<Point>()
  const index = points?.[0]?.index ?? null

  React.useEffect(() => onChange(index), [index, onChange])

  return null
}

export function AreaChartInteractive() {
  const id = React.useId()
  const [range, setRange] = React.useState<Range>("1M")
  const [hovered, setHovered] = React.useState<number | null>(null)
  const [released, setReleased] = React.useState(false)
  const active = released ? null : hovered
  const points = React.useMemo(() => resample(generate(range)), [range])
  const target = React.useMemo(
    () => points.map((point) => point.price),
    [points]
  )
  const animated = useMorph(target)
  const data = points.map((point, index) => ({
    ...point,
    price: animated[index],
  }))

  const opening = points[0]
  const current = points[active ?? points.length - 1]
  const baseline = data[0]
  if (!opening || !current || !baseline) return null

  const first = opening.price
  const change = current.price - first
  const rising = change >= 0
  const prices = points.map((point) => point.price)
  const shown = animated
  const min = Math.min(...shown)
  const max = Math.max(...shown)
  const padding = (max - min) * 0.12
  const chartConfig = {
    price: {
      label: "Price",
      color: rising ? "var(--color-green-500)" : "var(--destructive)",
    },
  } satisfies ChartConfig

  const stats = [
    ["Open", priceFormat.format(first)],
    ["High", priceFormat.format(Math.max(...prices))],
    ["Low", priceFormat.format(Math.min(...prices))],
    ["Volume", range === "1D" ? "41.2M" : "1.24B"],
  ]

  return (
    <Card variant="filled" size="sm" className="[--card-spacing:--spacing(5)]">
      <CardHeader className="flex flex-wrap items-start justify-between gap-4">
        <div className="flex min-w-56 flex-1 flex-col gap-0.5">
          <p className="flex items-baseline gap-2">
            <span className="text-2xl font-semibold tracking-tight">ACME</span>
            <span className="text-base text-muted-foreground">Acme Corp.</span>
          </p>
          <p className="flex flex-wrap items-baseline gap-2.5">
            <span className="text-3xl font-semibold tracking-tight tabular-nums">
              ${priceFormat.format(current.price)}
            </span>
            <span
              data-trend={rising ? "up" : "down"}
              className="text-base font-semibold tabular-nums data-[trend=down]:text-destructive data-[trend=up]:text-green-600 dark:data-[trend=up]:text-green-400"
            >
              {changeFormat.format(change)} (
              {priceFormat.format(Math.abs((change / first) * 100))}%)
            </span>
          </p>
          <p className="min-h-5 text-sm text-muted-foreground">
            {active === null ? RANGES[range].caption : current.label}
          </p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[range]}
          onValueChange={(value: string[]) => {
            if (value[0]) setRange(value[0] as Range)
          }}
          aria-label="Time range"
        >
          {(Object.keys(RANGES) as Range[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm">
              {key}
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-4">
        <ChartContainer
          config={chartConfig}
          onPointerDownCapture={() => setReleased(false)}
          onPointerUpCapture={(event) => {
            if (event.pointerType !== "mouse") setReleased(true)
          }}
          onPointerCancelCapture={() => setReleased(true)}
          onPointerMoveCapture={(event) => {
            if (event.pointerType === "mouse") setReleased(false)
          }}
          onKeyDownCapture={() => setReleased(false)}
          className="aspect-auto h-72 w-full touch-pan-y [&_.recharts-area-area]:transition-[fill] [&_.recharts-area-curve]:transition-[stroke] [&_.recharts-area-curve]:duration-500 [&_stop]:transition-[stop-color] [&_stop]:duration-500"
        >
          <AreaChart
            accessibilityLayer
            data={data}
            margin={{ top: 10, right: 0, left: 0, bottom: 0 }}
          >
            <defs>
              <linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-price)"
                  stopOpacity={0.3}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-price)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="index"
              type="number"
              domain={["dataMin", "dataMax"]}
              ticks={tickIndexes(points, 6)}
              tickFormatter={(index: number) => points[index]?.tick ?? ""}
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              minTickGap={4}
            />
            <YAxis
              orientation="right"
              domain={[min - padding, max + padding]}
              tickFormatter={(value: number) => Math.round(value).toString()}
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              tickCount={5}
              width={40}
            />
            <ReferenceLine
              y={baseline.price}
              stroke="var(--muted-foreground)"
              strokeDasharray="2 3"
            />
            <ChartTooltip
              active={released ? false : undefined}
              cursor={
                released
                  ? false
                  : { stroke: "var(--muted-foreground)", strokeWidth: 1 }
              }
              content={() => null}
            />
            <Area
              dataKey="price"
              type="linear"
              stroke="var(--color-price)"
              strokeWidth={2}
              fill={`url(#${id})`}
              isAnimationActive={false}
              activeDot={
                released
                  ? false
                  : {
                      r: 5,
                      fill: "var(--color-price)",
                      stroke: "var(--muted)",
                      strokeWidth: 2,
                    }
              }
            />
            <ActivePoint onChange={setHovered} />
          </AreaChart>
        </ChartContainer>
        <dl className="grid grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] gap-x-6">
          {stats.map(([term, value]) => (
            <div
              key={term}
              className="flex items-center gap-2 border-b border-border py-1.75 text-sm"
            >
              <dt className="flex-1 text-muted-foreground">{term}</dt>
              <dd className="font-semibold tabular-nums">{value}</dd>
            </div>
          ))}
        </dl>
      </CardContent>
    </Card>
  )
}
```

A stock-style price chart with range toggles from one day to five years. Scrubbing the plot updates the price, change and date in the header, and switching ranges morphs the line into its new shape. Use it as a starting point for financial or any time-series dashboard where readers drill into time ranges.

Replace the seeded `generate` function with your own data per range, one price and one label per point, and edit `RANGES` to change the toggles. The stats row under the chart, including volume, is static. There is no floating tooltip: the header shows every readout and returns to the latest price when a touch ends. The line turns green or red as the price at the cursor is above or below the opening price, and the morph is skipped when reduced motion is preferred.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-interactive
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-interactive
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-interactive.tsx"
"use client"

import * as React from "react"
import {
  Area,
  AreaChart,
  CartesianGrid,
  ReferenceLine,
  useActiveTooltipDataPoints,
  XAxis,
  YAxis,
} from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
} from "@/components/ui/chart"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Range = "1D" | "1W" | "1M" | "3M" | "1Y" | "5Y"

type Point = { index: number; price: number; label: string; tick: string }

const RANGES: Record<
  Range,
  {
    points: number
    seed: number
    volatility: number
    drift: number
    caption: string
  }
> = {
  "1D": {
    points: 78,
    seed: 11,
    volatility: 0.0025,
    drift: 0.46,
    caption: "Today",
  },
  "1W": {
    points: 35,
    seed: 23,
    volatility: 0.004,
    drift: 0.46,
    caption: "Past week",
  },
  "1M": {
    points: 22,
    seed: 37,
    volatility: 0.012,
    drift: 0.53,
    caption: "Past month",
  },
  "3M": {
    points: 64,
    seed: 41,
    volatility: 0.014,
    drift: 0.46,
    caption: "Past 3 months",
  },
  "1Y": {
    points: 52,
    seed: 59,
    volatility: 0.03,
    drift: 0.46,
    caption: "Past year",
  },
  "5Y": {
    points: 60,
    seed: 73,
    volatility: 0.045,
    drift: 0.46,
    caption: "Past 5 years",
  },
}

const LAST_PRICE = 254.32
const END = new Date(2026, 9, 6)
const SAMPLES = 80
const MORPH_DURATION = 520

const priceFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
})
const changeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
  signDisplay: "always",
})
const dayFormat = new Intl.DateTimeFormat("en-US", {
  month: "short",
  day: "numeric",
})
const weekdayFormat = new Intl.DateTimeFormat("en-US", { weekday: "short" })
const monthFormat = new Intl.DateTimeFormat("en-US", { month: "short" })
const monthYearFormat = new Intl.DateTimeFormat("en-US", {
  month: "long",
  year: "numeric",
})

function businessDays(count: number) {
  const days: Date[] = []
  const day = new Date(END)
  while (days.length < count) {
    if (day.getDay() % 6) days.unshift(new Date(day))
    day.setDate(day.getDate() - 1)
  }
  return days
}

function generate(range: Range): Point[] {
  const { points, seed, volatility, drift } = RANGES[range]
  let state = seed
  let value = 100
  const values = Array.from({ length: points }, () => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - drift) * volatility
    return value
  })
  const last = values.at(-1)
  if (last === undefined) return []
  const scale = LAST_PRICE / last
  const days = businessDays(points)
  const week = businessDays(5)

  return values.map((raw, index) => {
    const price = Number((raw * scale).toFixed(2))
    if (range === "1D") {
      const minutes = 570 + index * 5
      const hour = Math.floor(minutes / 60)
      const minute = minutes % 60
      const time = `${hour}:${String(minute).padStart(2, "0")}`
      return {
        index,
        price,
        label: time,
        tick: minute === 0 ? `${hour}:00` : "",
      }
    }
    if (range === "1W") {
      const day = week[Math.floor(index / 7)]
      const weekday = weekdayFormat.format(day)
      return {
        index,
        price,
        label: `${weekday} ${10 + (index % 7)}:00`,
        tick: index % 7 === 0 ? weekday : "",
      }
    }
    if (range === "1M" || range === "3M") {
      const label = dayFormat.format(days[index])
      return { index, price, label, tick: label }
    }
    if (range === "1Y") {
      const day = new Date(END)
      day.setDate(day.getDate() - (points - 1 - index) * 7)
      return {
        index,
        price,
        label: `${dayFormat.format(day)}, ${day.getFullYear()}`,
        tick: monthFormat.format(day),
      }
    }
    const month = new Date(
      END.getFullYear(),
      END.getMonth() - (points - 1 - index),
      1
    )
    return {
      index,
      price,
      label: monthYearFormat.format(month),
      tick: String(month.getFullYear()),
    }
  })
}

function resample(source: Point[]) {
  const samples: Point[] = []
  let previous = -1
  for (let index = 0; index < SAMPLES; index++) {
    const position = (index * (source.length - 1)) / (SAMPLES - 1)
    const from = Math.floor(position)
    const to = Math.min(source.length - 1, from + 1)
    const nearest = Math.round(position)
    const start = source[from]
    const end = source[to]
    const closest = source[nearest]
    if (!start || !end || !closest) return samples
    const price = start.price + (end.price - start.price) * (position - from)
    samples.push({
      index,
      price: Number(price.toFixed(2)),
      label: closest.label,
      tick: nearest !== previous ? closest.tick : "",
    })
    previous = nearest
  }
  return samples
}

function tickIndexes(points: Point[], max: number) {
  const ticks = points
    .filter(
      (point, index) => point.tick && point.tick !== points[index - 1]?.tick
    )
    .map((point) => point.index)
  if (ticks.length <= max) return ticks
  const step = Math.ceil(ticks.length / max)
  return ticks.filter((_, index) => index % step === 0)
}

function useMorph(target: number[]) {
  const [values, setValues] = React.useState(target)
  const valuesRef = React.useRef(values)

  React.useEffect(() => {
    const from = valuesRef.current
    if (
      target.length === from.length &&
      target.every((value, index) => value === from[index])
    )
      return
    const reduced = window.matchMedia(
      "(prefers-reduced-motion: reduce)"
    ).matches
    const start = performance.now()
    let frame = 0
    const step = () => {
      const progress = reduced
        ? 1
        : Math.min(1, (performance.now() - start) / MORPH_DURATION)
      const eased = 1 - (1 - progress) ** 3
      const next =
        progress < 1
          ? target.map((value, index) => {
              const origin = from[index] ?? value
              return origin + (value - origin) * eased
            })
          : target
      valuesRef.current = next
      setValues(next)
      if (progress < 1) frame = requestAnimationFrame(step)
    }
    frame = requestAnimationFrame(step)
    return () => cancelAnimationFrame(frame)
  }, [target])

  return values
}

function ActivePoint({
  onChange,
}: {
  onChange: (index: number | null) => void
}) {
  const points = useActiveTooltipDataPoints<Point>()
  const index = points?.[0]?.index ?? null

  React.useEffect(() => onChange(index), [index, onChange])

  return null
}

export function AreaChartInteractive() {
  const id = React.useId()
  const [range, setRange] = React.useState<Range>("1M")
  const [hovered, setHovered] = React.useState<number | null>(null)
  const [released, setReleased] = React.useState(false)
  const active = released ? null : hovered
  const points = React.useMemo(() => resample(generate(range)), [range])
  const target = React.useMemo(
    () => points.map((point) => point.price),
    [points]
  )
  const animated = useMorph(target)
  const data = points.map((point, index) => ({
    ...point,
    price: animated[index],
  }))

  const opening = points[0]
  const current = points[active ?? points.length - 1]
  const baseline = data[0]
  if (!opening || !current || !baseline) return null

  const first = opening.price
  const change = current.price - first
  const rising = change >= 0
  const prices = points.map((point) => point.price)
  const shown = animated
  const min = Math.min(...shown)
  const max = Math.max(...shown)
  const padding = (max - min) * 0.12
  const chartConfig = {
    price: {
      label: "Price",
      color: rising ? "var(--color-green-500)" : "var(--destructive)",
    },
  } satisfies ChartConfig

  const stats = [
    ["Open", priceFormat.format(first)],
    ["High", priceFormat.format(Math.max(...prices))],
    ["Low", priceFormat.format(Math.min(...prices))],
    ["Volume", range === "1D" ? "41.2M" : "1.24B"],
  ]

  return (
    <Card variant="filled" size="sm" className="[--card-spacing:--spacing(5)]">
      <CardHeader className="flex flex-wrap items-start justify-between gap-4">
        <div className="flex min-w-56 flex-1 flex-col gap-0.5">
          <p className="flex items-baseline gap-2">
            <span className="text-2xl font-semibold tracking-tight">ACME</span>
            <span className="text-base text-muted-foreground">Acme Corp.</span>
          </p>
          <p className="flex flex-wrap items-baseline gap-2.5">
            <span className="text-3xl font-semibold tracking-tight tabular-nums">
              ${priceFormat.format(current.price)}
            </span>
            <span
              data-trend={rising ? "up" : "down"}
              className="text-base font-semibold tabular-nums data-[trend=down]:text-destructive data-[trend=up]:text-green-600 dark:data-[trend=up]:text-green-400"
            >
              {changeFormat.format(change)} (
              {priceFormat.format(Math.abs((change / first) * 100))}%)
            </span>
          </p>
          <p className="min-h-5 text-sm text-muted-foreground">
            {active === null ? RANGES[range].caption : current.label}
          </p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[range]}
          onValueChange={(value: string[]) => {
            if (value[0]) setRange(value[0] as Range)
          }}
          aria-label="Time range"
        >
          {(Object.keys(RANGES) as Range[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm">
              {key}
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-4">
        <ChartContainer
          config={chartConfig}
          onPointerDownCapture={() => setReleased(false)}
          onPointerUpCapture={(event) => {
            if (event.pointerType !== "mouse") setReleased(true)
          }}
          onPointerCancelCapture={() => setReleased(true)}
          onPointerMoveCapture={(event) => {
            if (event.pointerType === "mouse") setReleased(false)
          }}
          onKeyDownCapture={() => setReleased(false)}
          className="aspect-auto h-72 w-full touch-pan-y [&_.recharts-area-area]:transition-[fill] [&_.recharts-area-curve]:transition-[stroke] [&_.recharts-area-curve]:duration-500 [&_stop]:transition-[stop-color] [&_stop]:duration-500"
        >
          <AreaChart
            accessibilityLayer
            data={data}
            margin={{ top: 10, right: 0, left: 0, bottom: 0 }}
          >
            <defs>
              <linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
                <stop
                  offset="0%"
                  stopColor="var(--color-price)"
                  stopOpacity={0.3}
                />
                <stop
                  offset="100%"
                  stopColor="var(--color-price)"
                  stopOpacity={0.02}
                />
              </linearGradient>
            </defs>
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="index"
              type="number"
              domain={["dataMin", "dataMax"]}
              ticks={tickIndexes(points, 6)}
              tickFormatter={(index: number) => points[index]?.tick ?? ""}
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              minTickGap={4}
            />
            <YAxis
              orientation="right"
              domain={[min - padding, max + padding]}
              tickFormatter={(value: number) => Math.round(value).toString()}
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              tickCount={5}
              width={40}
            />
            <ReferenceLine
              y={baseline.price}
              stroke="var(--muted-foreground)"
              strokeDasharray="2 3"
            />
            <ChartTooltip
              active={released ? false : undefined}
              cursor={
                released
                  ? false
                  : { stroke: "var(--muted-foreground)", strokeWidth: 1 }
              }
              content={() => null}
            />
            <Area
              dataKey="price"
              type="linear"
              stroke="var(--color-price)"
              strokeWidth={2}
              fill={`url(#${id})`}
              isAnimationActive={false}
              activeDot={
                released
                  ? false
                  : {
                      r: 5,
                      fill: "var(--color-price)",
                      stroke: "var(--muted)",
                      strokeWidth: 2,
                    }
              }
            />
            <ActivePoint onChange={setHovered} />
          </AreaChart>
        </ChartContainer>
        <dl className="grid grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] gap-x-6">
          {stats.map(([term, value]) => (
            <div
              key={term}
              className="flex items-center gap-2 border-b border-border py-1.75 text-sm"
            >
              <dt className="flex-1 text-muted-foreground">{term}</dt>
              <dd className="font-semibold tabular-nums">{value}</dd>
            </div>
          ))}
        </dl>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartInteractive } from "@/components/charts/area-chart-interactive"
```

```tsx
<AreaChartInteractive />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-interactive.tsx"
import { cn } from "cn"
import * as React from "react"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Range = "1D" | "1W" | "1M" | "3M" | "1Y" | "5Y"

type Point = { index: number; price: number; label: string; tick: string }

const RANGES: Record<
  Range,
  {
    points: number
    seed: number
    volatility: number
    drift: number
    caption: string
  }
> = {
  "1D": {
    points: 78,
    seed: 11,
    volatility: 0.0025,
    drift: 0.46,
    caption: "Today",
  },
  "1W": {
    points: 35,
    seed: 23,
    volatility: 0.004,
    drift: 0.46,
    caption: "Past week",
  },
  "1M": {
    points: 22,
    seed: 37,
    volatility: 0.012,
    drift: 0.53,
    caption: "Past month",
  },
  "3M": {
    points: 64,
    seed: 41,
    volatility: 0.014,
    drift: 0.46,
    caption: "Past 3 months",
  },
  "1Y": {
    points: 52,
    seed: 59,
    volatility: 0.03,
    drift: 0.46,
    caption: "Past year",
  },
  "5Y": {
    points: 60,
    seed: 73,
    volatility: 0.045,
    drift: 0.46,
    caption: "Past 5 years",
  },
}

const LAST_PRICE = 254.32
const END = new Date(2026, 9, 6)
const SAMPLES = 80

const MONTHS = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
]

const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

function shortMonth(date: Date) {
  return (MONTHS[date.getMonth()] ?? "").slice(0, 3)
}

function shortDay(date: Date) {
  return `${shortMonth(date)} ${date.getDate()}`
}

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function businessDays(count: number) {
  const days: Date[] = []
  const day = new Date(END)
  while (days.length < count) {
    if (day.getDay() % 6) days.unshift(new Date(day))
    day.setDate(day.getDate() - 1)
  }
  return days
}

function generate(range: Range): Point[] {
  const { points, seed, volatility, drift } = RANGES[range]
  let state = seed
  let value = 100
  const values = Array.from({ length: points }, () => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - drift) * volatility
    return value
  })
  const last = values.at(-1)
  if (last === undefined) return []
  const scale = LAST_PRICE / last
  const days = businessDays(points)
  const week = businessDays(5)

  return values.map((raw, index) => {
    const price = Number((raw * scale).toFixed(2))
    if (range === "1D") {
      const minutes = 570 + index * 5
      const hour = Math.floor(minutes / 60)
      const minute = minutes % 60
      const time = `${hour}:${String(minute).padStart(2, "0")}`
      return {
        index,
        price,
        label: time,
        tick: minute === 0 ? `${hour}:00` : "",
      }
    }
    if (range === "1W") {
      const day = week[Math.floor(index / 7)] ?? END
      const weekday = WEEKDAYS[day.getDay()] ?? ""
      return {
        index,
        price,
        label: `${weekday} ${10 + (index % 7)}:00`,
        tick: index % 7 === 0 ? weekday : "",
      }
    }
    if (range === "1M" || range === "3M") {
      const label = shortDay(days[index] ?? END)
      return { index, price, label, tick: label }
    }
    if (range === "1Y") {
      const day = new Date(END)
      day.setDate(day.getDate() - (points - 1 - index) * 7)
      return {
        index,
        price,
        label: `${shortDay(day)}, ${day.getFullYear()}`,
        tick: shortMonth(day),
      }
    }
    const month = new Date(
      END.getFullYear(),
      END.getMonth() - (points - 1 - index),
      1
    )
    return {
      index,
      price,
      label: `${MONTHS[month.getMonth()]} ${month.getFullYear()}`,
      tick: String(month.getFullYear()),
    }
  })
}

function resample(source: Point[]) {
  const samples: Point[] = []
  let previous = -1
  for (let index = 0; index < SAMPLES; index++) {
    const position = (index * (source.length - 1)) / (SAMPLES - 1)
    const from = Math.floor(position)
    const to = Math.min(source.length - 1, from + 1)
    const nearest = Math.round(position)
    const start = source[from]
    const end = source[to]
    const closest = source[nearest]
    if (!start || !end || !closest) return samples
    const price = start.price + (end.price - start.price) * (position - from)
    samples.push({
      index,
      price: Number(price.toFixed(2)),
      label: closest.label,
      tick: nearest !== previous ? closest.tick : "",
    })
    previous = nearest
  }
  return samples
}

function tickIndexes(points: Point[], max: number) {
  const ticks = points
    .filter(
      (point, index) => point.tick && point.tick !== points[index - 1]?.tick
    )
    .map((point) => point.index)
  if (ticks.length <= max) return ticks
  const step = Math.ceil(ticks.length / max)
  return ticks.filter((_, index) => index % step === 0)
}

export function AreaChartInteractive() {
  const [range, setRange] = React.useState<Range>("1M")
  const [active, setActive] = React.useState<number | null>(null)
  const points = React.useMemo(() => resample(generate(range)), [range])

  const opening = points[0]
  const current = points[active ?? points.length - 1]
  if (!opening || !current) return null

  const first = opening.price
  const change = current.price - first
  const rising = change >= 0
  const prices = points.map((point) => point.price)
  const min = Math.min(...prices)
  const max = Math.max(...prices)
  const padding = (max - min) * 0.12
  const color = rising ? "green-500" : "destructive"
  const chartConfig = {
    price: { label: "Price", color },
  } satisfies ChartConfig

  const stats = [
    ["Open", formatPrice(first)],
    ["High", formatPrice(max)],
    ["Low", formatPrice(min)],
    ["Volume", range === "1D" ? "41.2M" : "1.24B"],
  ]

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View className="min-w-56 grow gap-0.5">
          <View className="flex-row items-baseline gap-2">
            <Text className="text-2xl font-semibold tracking-tight">ACME</Text>
            <Text className="text-base text-muted-foreground">Acme Corp.</Text>
          </View>
          <View className="flex-row flex-wrap items-baseline gap-2.5">
            <Text className="text-3xl font-semibold tracking-tight tabular-nums">
              ${formatPrice(current.price)}
            </Text>
            <Text
              className={cn(
                "text-base font-semibold tabular-nums",
                rising
                  ? "text-green-600 dark:text-green-400"
                  : "text-destructive"
              )}
            >
              {formatPrice(change, true)} (
              {formatPrice(Math.abs((change / first) * 100))}%)
            </Text>
          </View>
          <Text className="min-h-5 text-sm text-muted-foreground">
            {active === null ? RANGES[range].caption : current.label}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[range]}
          onValueChange={(value) => {
            if (value[0]) setRange(value[0] as Range)
          }}
          accessibilityLabel="Time range"
        >
          {(Object.keys(RANGES) as Range[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm">
              <Text>{key}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-4">
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="ACME price"
          className="h-72 w-full"
        >
          <AreaChart
            data={points}
            margin={{ top: 10, right: 0, left: 0, bottom: 0 }}
            onActiveIndexChange={setActive}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="index"
              type="number"
              domain={["dataMin", "dataMax"]}
              ticks={tickIndexes(points, 6)}
              tickFormatter={(index: number) => points[index]?.tick ?? ""}
              tickMargin={8}
              minTickGap={4}
            />
            <YAxis
              orientation="right"
              domain={[min - padding, max + padding]}
              tickFormatter={(value: number) => Math.round(value).toString()}
              tickMargin={6}
              tickCount={5}
              width={40}
            />
            <ReferenceLine
              y={first}
              stroke="muted-foreground"
              strokeDasharray="2 3"
            />
            <ChartTooltip
              content={() => null}
              cursor={{ stroke: "muted-foreground", strokeWidth: 1 }}
            />
            <Area
              isAnimationActive={false}
              dataKey="price"
              type="linear"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.3 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              activeDot={{
                r: 5,
                fill: color,
                stroke: "muted",
                strokeWidth: 2,
              }}
            />
          </AreaChart>
        </ChartContainer>
        <View className="flex-row flex-wrap gap-x-6">
          {stats.map(([term, value]) => (
            <View
              key={term}
              className="min-w-36 grow basis-0 flex-row items-center gap-2 border-b border-border py-1.75"
            >
              <Text className="grow text-sm text-muted-foreground">{term}</Text>
              <Text className="text-sm font-semibold tabular-nums">
                {value}
              </Text>
            </View>
          ))}
        </View>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartInteractive.swift"
import Charts
import SwiftUI

private enum Period: String, CaseIterable {
  case day = "1D"
  case week = "1W"
  case month = "1M"
  case quarter = "3M"
  case year = "1Y"
  case fiveYears = "5Y"

  var settings: (points: Int, seed: Int, volatility: Double, drift: Double) {
    switch self {
    case .day: (78, 11, 0.0025, 0.46)
    case .week: (35, 23, 0.004, 0.46)
    case .month: (22, 37, 0.012, 0.53)
    case .quarter: (64, 41, 0.014, 0.46)
    case .year: (52, 59, 0.03, 0.46)
    case .fiveYears: (60, 73, 0.045, 0.46)
    }
  }

  var caption: String {
    switch self {
    case .day: "Today"
    case .week: "Past week"
    case .month: "Past month"
    case .quarter: "Past 3 months"
    case .year: "Past year"
    case .fiveYears: "Past 5 years"
    }
  }
}

private struct Point {
  let index: Int
  let price: Double
  let label: String
  let tick: String
}

private let lastPrice = 254.32
private let samples = 80

private var calendar: Calendar {
  Calendar(identifier: .gregorian)
}

private var end: Date {
  calendar.date(from: DateComponents(year: 2026, month: 10, day: 6)) ?? .now
}

private func businessDays(_ count: Int) -> [Date] {
  var days: [Date] = []
  var day = end
  while days.count < count {
    let weekday = calendar.component(.weekday, from: day)
    if weekday != 1 && weekday != 7 { days.insert(day, at: 0) }
    day = calendar.date(byAdding: .day, value: -1, to: day) ?? day
  }
  return days
}

private func generate(_ range: Period, locale: Locale) -> [Point] {
  let settings = range.settings
  var state = settings.seed
  var value = 100.0
  let values = (0..<settings.points).map { _ in
    state = (state * 16807) % 2147483647
    value *= 1 + (Double(state - 1) / 2147483646 - settings.drift) * settings.volatility
    return value
  }
  guard let last = values.last else { return [] }
  let scale = lastPrice / last
  let days = businessDays(settings.points)
  let week = businessDays(5)
  let dayFormat = Date.FormatStyle.dateTime.month(.abbreviated).day().locale(locale)
  return values.enumerated().map { index, raw in
    let price = (raw * scale * 100).rounded() / 100
    switch range {
    case .day:
      let minutes = 570 + index * 5
      let hour = minutes / 60
      let minute = minutes % 60
      return Point(index: index, price: price, label: String(format: "%d:%02d", hour, minute), tick: minute == 0 ? "\(hour):00" : "")
    case .week:
      let weekday = week[index / 7].formatted(.dateTime.weekday(.abbreviated).locale(locale))
      return Point(index: index, price: price, label: "\(weekday) \(10 + index % 7):00", tick: index % 7 == 0 ? weekday : "")
    case .month, .quarter:
      let label = days[index].formatted(dayFormat)
      return Point(index: index, price: price, label: label, tick: label)
    case .year:
      let day = calendar.date(byAdding: .day, value: -(settings.points - 1 - index) * 7, to: end) ?? end
      return Point(
        index: index,
        price: price,
        label: "\(day.formatted(dayFormat)), \(calendar.component(.year, from: day))",
        tick: day.formatted(.dateTime.month(.abbreviated).locale(locale))
      )
    case .fiveYears:
      let month = calendar.date(byAdding: .month, value: -(settings.points - 1 - index), to: end) ?? end
      return Point(
        index: index,
        price: price,
        label: month.formatted(.dateTime.month(.wide).year().locale(locale)),
        tick: "\(calendar.component(.year, from: month))"
      )
    }
  }
}

private func resample(_ source: [Point]) -> [Point] {
  guard source.count > 1 else { return source }
  var result: [Point] = []
  var previous = -1
  for index in 0..<samples {
    let position = Double(index * (source.count - 1)) / Double(samples - 1)
    let from = Int(position)
    let to = min(source.count - 1, from + 1)
    let nearest = Int(position.rounded())
    let start = source[from]
    let finish = source[to]
    let closest = source[nearest]
    let price = start.price + (finish.price - start.price) * (position - Double(from))
    result.append(Point(index: index, price: (price * 100).rounded() / 100, label: closest.label, tick: nearest != previous ? closest.tick : ""))
    previous = nearest
  }
  return result
}

private func tickIndexes(_ points: [Point], max: Int) -> [Int] {
  let ticks = points.enumerated()
    .filter { index, point in !point.tick.isEmpty && (index == 0 || point.tick != points[index - 1].tick) }
    .map(\.element.index)
  guard ticks.count > max else { return ticks }
  let step = Int((Double(ticks.count) / Double(max)).rounded(.up))
  return ticks.enumerated().filter { $0.offset % step == 0 }.map(\.element)
}

public struct AreaChartInteractive: View {
  @State private var range: Period = .month
  @State private var selection: Int?
  @Environment(\.locale) private var locale
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init() {}

  private var rangeBinding: Binding<Period?> {
    Binding(get: { range }, set: { if let value = $0 { range = value } })
  }

  public var body: some View {
    let points = resample(generate(range, locale: locale))
    let prices = points.map(\.price)
    let first = points.first?.price ?? 0
    let current = points[selection ?? points.count - 1]
    let change = current.price - first
    let rising = change >= 0
    let low = prices.min() ?? 0
    let high = prices.max() ?? 1
    let padding = (high - low) * 0.12
    let chartConfig: ChartConfig = ["price": .init("Price", color: rising ? Palette.green500 : EsuissColor.destructive)]
    let color = chartConfig.color("price")
    let price = FloatingPointFormatStyle<Double>.number.precision(.fractionLength(2)).locale(locale)
    let stats: [(String, String)] = [
      ("Open", first.formatted(price)),
      ("High", high.formatted(price)),
      ("Low", low.formatted(price)),
      ("Volume", range == .day ? "41.2M" : "1.24B"),
    ]
    Card(.filled, size: .sm) {
      VStack(alignment: .leading, spacing: 16) {
        VStack(alignment: .leading, spacing: 2) {
          HStack(alignment: .firstTextBaseline, spacing: 8) {
            Text(verbatim: "ACME")
              .textStyle(.xl2, weight: .semibold)
            Text(verbatim: "Acme Corp.")
              .textStyle(.base)
              .foregroundStyle(EsuissColor.mutedForeground)
          }
          HStack(alignment: .firstTextBaseline, spacing: 10) {
            Text(verbatim: "$\(current.price.formatted(price))")
              .textStyle(.xl3, weight: .semibold)
              .monospacedDigit()
            Text(verbatim: "\(change.formatted(price.sign(strategy: .always()))) (\(abs(change / first * 100).formatted(price))%)")
              .textStyle(.base, weight: .semibold)
              .monospacedDigit()
              .foregroundStyle(rising ? Color.adaptive(light: Palette.green600, dark: Palette.green400) : EsuissColor.destructive)
          }
          Text(LocalizedStringKey(selection == nil ? range.caption : current.label))
            .textStyle(.sm)
            .foregroundStyle(EsuissColor.mutedForeground)
            .frame(minHeight: 20)
        }
        ToggleGroup(selection: rangeBinding, size: .sm, spacing: 0) {
          ForEach(Period.allCases, id: \.self) { item in
            ToggleGroupItem(LocalizedStringKey(item.rawValue), value: item)
          }
        }
        .accessibilityLabel("Time range")
      }
      .padding(.horizontal, 16)
      CardContent {
        VStack(alignment: .leading, spacing: 16) {
          ChartContainer(config: chartConfig) {
            Chart {
              RuleMark(y: .value("Open", first))
                .lineStyle(StrokeStyle(lineWidth: 1, dash: [2, 3]))
                .foregroundStyle(EsuissColor.mutedForeground)
              ForEach(points, id: \.index) { point in
                AreaMark(x: .value("Time", point.index), yStart: .value("Base", low - padding), yEnd: .value("Price", point.price))
                  .interpolationMethod(.linear)
                  .foregroundStyle(LinearGradient(colors: [color.opacity(0.3), color.opacity(0.02)], startPoint: .top, endPoint: .bottom))
                LineMark(x: .value("Time", point.index), y: .value("Price", point.price))
                  .interpolationMethod(.linear)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(color)
              }
              if let selection {
                PointMark(x: .value("Time", selection), y: .value("Price", points[selection].price))
                  .symbol {
                    Circle()
                      .fill(color)
                      .stroke(EsuissColor.muted, lineWidth: 2)
                      .frame(width: 12, height: 12)
                  }
              }
            }
            .chartXScale(domain: 0...(points.count - 1))
            .chartYScale(domain: (low - padding)...(high + padding))
            .chartXAxis { ChartAxis.x(values: tickIndexes(points, max: 6)) { points[$0].tick } }
            .chartYAxis { ChartAxis.y(count: 5) { "\(Int($0.rounded()))" } }
            .animation(reduceMotion ? nil : .easeOut(duration: 0.52), value: range)
            .chartTooltip(
              x: points.map(\.index),
              labels: points.map(\.label),
              selection: $selection,
              accessibilityLabel: "ACME",
              items: { [ChartTooltipItem("price", value: points[$0].price)] }
            ) { _ in
              EmptyView()
            }
          }
          .frame(height: 288)
          LazyVGrid(columns: [GridItem(.adaptive(minimum: 144), spacing: 24)], spacing: 0) {
            ForEach(stats, id: \.0) { term, value in
              HStack(spacing: 8) {
                Text(LocalizedStringKey(term))
                  .foregroundStyle(EsuissColor.mutedForeground)
                  .frame(maxWidth: .infinity, alignment: .leading)
                Text(verbatim: value)
                  .fontWeight(.semibold)
                  .monospacedDigit()
              }
              .textStyle(.sm)
              .padding(.vertical, 7)
              .overlay(alignment: .bottom) {
                EsuissColor.border.frame(height: 1)
              }
              .accessibilityElement(children: .combine)
            }
          }
        }
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartInteractive.kt"
package com.esuiss.ui.charts

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Easing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartAxisOrientation
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCursor
import com.esuiss.ui.components.ChartDot
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.Separator
import com.esuiss.ui.components.ToggleGroup
import com.esuiss.ui.components.ToggleGroupItem
import com.esuiss.ui.components.ToggleSize
import com.esuiss.ui.components.formReducedMotion
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Typography
import java.text.NumberFormat
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.roundToInt

private class StockRange(val points: Int, val seed: Long, val volatility: Double, val drift: Double, val caption: String)

private class PricePoint(val index: Int, val price: Double, val label: String, val tick: String)

private val ranges = linkedMapOf(
    "1D" to StockRange(78, 11, 0.0025, 0.46, "Today"),
    "1W" to StockRange(35, 23, 0.004, 0.46, "Past week"),
    "1M" to StockRange(22, 37, 0.012, 0.53, "Past month"),
    "3M" to StockRange(64, 41, 0.014, 0.46, "Past 3 months"),
    "1Y" to StockRange(52, 59, 0.03, 0.46, "Past year"),
    "5Y" to StockRange(60, 73, 0.045, 0.46, "Past 5 years"),
)

private const val LAST_PRICE = 254.32

private const val SAMPLES = 80

private const val MORPH_DURATION = 520

private val MorphEasing = Easing { 1f - (1f - it) * (1f - it) * (1f - it) }

private fun end(): Calendar = Calendar.getInstance().apply {
    clear()
    set(2026, Calendar.OCTOBER, 6, 12, 0)
}

private fun format(pattern: String, date: Date) = SimpleDateFormat(pattern, Locale.US).format(date)

private fun businessDays(count: Int): List<Date> {
    val days = ArrayDeque<Date>()
    val day = end()
    while (days.size < count) {
        val weekday = day.get(Calendar.DAY_OF_WEEK)
        if (weekday != Calendar.SATURDAY && weekday != Calendar.SUNDAY) days.addFirst(day.time)
        day.add(Calendar.DAY_OF_MONTH, -1)
    }
    return days.toList()
}

private fun generate(range: String): List<PricePoint> {
    val spec = ranges.getValue(range)
    var state = spec.seed
    var value = 100.0
    val values = List(spec.points) {
        state = state * 16807 % 2147483647
        value *= 1 + ((state - 1) / 2147483646.0 - spec.drift) * spec.volatility
        value
    }
    val scale = LAST_PRICE / values.last()
    val days = businessDays(spec.points)
    val week = businessDays(5)
    return values.mapIndexed { index, raw ->
        val price = (raw * scale * 100).roundToInt() / 100.0
        when (range) {
            "1D" -> {
                val minutes = 570 + index * 5
                val hour = minutes / 60
                val minute = minutes % 60
                PricePoint(index, price, "$hour:${minute.toString().padStart(2, '0')}", if (minute == 0) "$hour:00" else "")
            }
            "1W" -> {
                val weekday = format("EEE", week[index / 7])
                PricePoint(index, price, "$weekday ${10 + index % 7}:00", if (index % 7 == 0) weekday else "")
            }
            "1M", "3M" -> {
                val label = format("MMM d", days[index])
                PricePoint(index, price, label, label)
            }
            "1Y" -> {
                val day = end().apply { add(Calendar.DAY_OF_MONTH, -(spec.points - 1 - index) * 7) }
                PricePoint(index, price, "${format("MMM d", day.time)}, ${day.get(Calendar.YEAR)}", format("MMM", day.time))
            }
            else -> {
                val month = end().apply {
                    set(Calendar.DAY_OF_MONTH, 1)
                    add(Calendar.MONTH, -(spec.points - 1 - index))
                }
                PricePoint(index, price, format("MMMM yyyy", month.time), month.get(Calendar.YEAR).toString())
            }
        }
    }
}

private fun resample(source: List<PricePoint>): List<PricePoint> {
    val samples = mutableListOf<PricePoint>()
    var previous = -1
    for (index in 0 until SAMPLES) {
        val position = index * (source.size - 1).toDouble() / (SAMPLES - 1)
        val from = position.toInt()
        val to = minOf(source.size - 1, from + 1)
        val nearest = position.roundToInt()
        val start = source[from]
        val stop = source[to]
        val closest = source[nearest]
        val price = start.price + (stop.price - start.price) * (position - from)
        samples += PricePoint(index, (price * 100).roundToInt() / 100.0, closest.label, if (nearest != previous) closest.tick else "")
        previous = nearest
    }
    return samples
}

private fun tickIndexes(points: List<PricePoint>, max: Int): List<Int> {
    val ticks = points.filterIndexed { index, point -> point.tick.isNotEmpty() && point.tick != points.getOrNull(index - 1)?.tick }.map { it.index }
    if (ticks.size <= max) return ticks
    val step = ceil(ticks.size / max.toDouble()).toInt()
    return ticks.filterIndexed { index, _ -> index % step == 0 }
}

private fun twoDigits(): NumberFormat = NumberFormat.getNumberInstance(Locale.US).apply {
    minimumFractionDigits = 2
    maximumFractionDigits = 2
}

@Composable
private fun rememberMorph(target: List<Double>): List<Double> {
    val reduced = formReducedMotion()
    var values by remember { mutableStateOf(target) }
    LaunchedEffect(target) {
        val from = values
        if (reduced || from == target) {
            values = target
            return@LaunchedEffect
        }
        Animatable(0f).animateTo(1f, tween(MORPH_DURATION, easing = MorphEasing)) {
            values = target.mapIndexed { index, price ->
                val origin = from.getOrNull(index) ?: price
                origin + (price - origin) * value
            }
        }
    }
    return values
}

@Composable
fun AreaChartInteractive(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    var range by remember { mutableStateOf("1M") }
    var active by remember { mutableStateOf<Int?>(null) }
    val points = remember(range) { resample(generate(range)) }
    val ticks = remember(points) { tickIndexes(points, 6) }
    val priceFormat = remember { twoDigits() }
    val first = points.first().price
    val current = points[active ?: (points.size - 1)]
    val change = current.price - first
    val rising = change >= 0
    val prices = points.map { it.price }
    val animated = rememberMorph(prices)
    val data = points.mapIndexed { index, point -> PricePoint(point.index, animated.getOrElse(index) { point.price }, point.label, point.tick) }
    val min = prices.min()
    val max = prices.max()
    val low = animated.min()
    val high = animated.max()
    val padding = (high - low) * 0.12
    val trend by animateColorAsState(if (rising) (if (colors.isDark) Palette.green400 else Palette.green600) else colors.destructive, tween(500), label = "trend")
    val chartConfig = ChartConfig("price" to ChartConfigItem("Price") { trend })
    val stats = listOf(
        "Open" to priceFormat.format(first),
        "High" to priceFormat.format(max),
        "Low" to priceFormat.format(min),
        "Volume" to if (range == "1D") "41.2M" else "1.24B",
    )
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
                Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
                    Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
                        BasicText("ACME", Modifier.alignByBaseline(), style = Typography.xl2.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold))
                        BasicText("Acme Corp.", Modifier.alignByBaseline(), style = Typography.base.copy(color = colors.mutedForeground))
                    }
                    Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
                        BasicText(
                            "$${priceFormat.format(current.price)}",
                            Modifier.alignByBaseline(),
                            style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                        )
                        BasicText(
                            "${if (rising) "+" else "-"}${priceFormat.format(abs(change))} (${priceFormat.format(abs(change / first * 100))}%)",
                            Modifier.alignByBaseline(),
                            style = Typography.base.copy(
                                color = if (rising) (if (colors.isDark) Palette.green400 else Palette.green600) else colors.destructive,
                                fontWeight = FontWeight.SemiBold,
                                fontFeatureSettings = "tnum",
                            ),
                        )
                    }
                    BasicText(
                        if (active == null) ranges.getValue(range).caption else current.label,
                        Modifier.heightIn(min = 20.dp),
                        style = Typography.sm.copy(color = colors.mutedForeground),
                    )
                }
                ToggleGroup(
                    value = range,
                    onValueChange = { value ->
                        if (value != null) {
                            range = value
                            active = null
                        }
                    },
                    size = ToggleSize.Sm,
                    spacing = 0,
                ) {
                    for (key in ranges.keys) ToggleGroupItem(key, key)
                }
            }
        }
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
                ChartContainer(
                    chartConfig,
                    Modifier
                        .fillMaxWidth()
                        .height(288.dp),
                ) {
                    val tickByLabel = points.filter { it.index in ticks }.associate { it.label to it.tick }
                    AreaChart(
                        data,
                        margin = ChartMargin(top = 10.dp, right = 0.dp, bottom = 0.dp, left = 0.dp),
                        accessibilityLabel = "ACME, ${ranges.getValue(range).caption}",
                        selectedIndex = active,
                        onSelectedIndexChange = { active = it },
                    ) {
                        CartesianGrid(strokeDasharray = listOf(2f, 4f))
                        XAxis(label = { it.label }, tickMargin = 8.dp, ticks = ticks, tickFormatter = { tickByLabel[it] ?: "" })
                        YAxis(
                            orientation = ChartAxisOrientation.Right,
                            tickMargin = 6.dp,
                            width = 40.dp,
                            domain = (low - padding)..(high + padding),
                            tickFormatter = { it.roundToInt().toString() },
                        )
                        ReferenceLine(first, stroke = colors.mutedForeground, strokeDasharray = listOf(2f, 3f))
                        ChartTooltip(cursor = ChartCursor(colors.mutedForeground)) { }
                        Area(
                            "price",
                            value = { it.price },
                            strokeWidth = 2.dp,
                            fill = ChartFill.VerticalGradient(topAlpha = 0.3f, bottomAlpha = 0.02f),
                            activeDot = ChartDot(5.dp, strokeColor = colors.muted, strokeWidth = 2.dp),
                            isAnimationActive = false,
                        )
                    }
                }
                Column {
                    for (pair in stats.chunked(2)) {
                        Row(horizontalArrangement = Arrangement.spacedBy(24.dp)) {
                            for ((term, value) in pair) {
                                Column(Modifier.weight(1f)) {
                                    Row(Modifier.padding(vertical = 7.dp)) {
                                        BasicText(term, Modifier.weight(1f), style = Typography.sm.copy(color = colors.mutedForeground))
                                        BasicText(
                                            value,
                                            style = Typography.sm.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                                        )
                                    }
                                    Separator()
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```

**React Native**

One price series drawn as a linear area with a fading gradient, a value axis on the right and a dashed `ReferenceLine` at the opening price. A `ToggleGroup` switches between 1D, 1W, 1M, 3M, 1Y and 5Y. Touching the plot reports the point through `onActiveIndexChange`, and the header updates the price, change and date for that point. The area turns green or red depending on whether the price is up or down, and open, high, low and volume sit below the chart. The area sets `isAnimationActive={false}`, so it draws without the enter animation and switches ranges instantly.

Replace `generate()` with your price history for each range, and set the symbol, company name and `LAST_PRICE`. Volume values are hard-coded in `stats`. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-interactive
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-interactive --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-interactive
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-interactive --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into `components/charts/area-chart-interactive.tsx`:

- `uniwind/components/charts/area-chart-interactive.tsx`: shown above

4. Update the import paths to match your project setup.

**NativeWind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

3. Copy and paste the following code into `components/charts/area-chart-interactive.tsx`:

```tsx title="nativewind/components/charts/area-chart-interactive.tsx"
import { cn } from "cn"
import * as React from "react"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Range = "1D" | "1W" | "1M" | "3M" | "1Y" | "5Y"

type Point = { index: number; price: number; label: string; tick: string }

const RANGES: Record<
  Range,
  {
    points: number
    seed: number
    volatility: number
    drift: number
    caption: string
  }
> = {
  "1D": {
    points: 78,
    seed: 11,
    volatility: 0.0025,
    drift: 0.46,
    caption: "Today",
  },
  "1W": {
    points: 35,
    seed: 23,
    volatility: 0.004,
    drift: 0.46,
    caption: "Past week",
  },
  "1M": {
    points: 22,
    seed: 37,
    volatility: 0.012,
    drift: 0.53,
    caption: "Past month",
  },
  "3M": {
    points: 64,
    seed: 41,
    volatility: 0.014,
    drift: 0.46,
    caption: "Past 3 months",
  },
  "1Y": {
    points: 52,
    seed: 59,
    volatility: 0.03,
    drift: 0.46,
    caption: "Past year",
  },
  "5Y": {
    points: 60,
    seed: 73,
    volatility: 0.045,
    drift: 0.46,
    caption: "Past 5 years",
  },
}

const LAST_PRICE = 254.32
const END = new Date(2026, 9, 6)
const SAMPLES = 80

const MONTHS = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
]

const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

function shortMonth(date: Date) {
  return (MONTHS[date.getMonth()] ?? "").slice(0, 3)
}

function shortDay(date: Date) {
  return `${shortMonth(date)} ${date.getDate()}`
}

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function businessDays(count: number) {
  const days: Date[] = []
  const day = new Date(END)
  while (days.length < count) {
    if (day.getDay() % 6) days.unshift(new Date(day))
    day.setDate(day.getDate() - 1)
  }
  return days
}

function generate(range: Range): Point[] {
  const { points, seed, volatility, drift } = RANGES[range]
  let state = seed
  let value = 100
  const values = Array.from({ length: points }, () => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - drift) * volatility
    return value
  })
  const last = values.at(-1)
  if (last === undefined) return []
  const scale = LAST_PRICE / last
  const days = businessDays(points)
  const week = businessDays(5)

  return values.map((raw, index) => {
    const price = Number((raw * scale).toFixed(2))
    if (range === "1D") {
      const minutes = 570 + index * 5
      const hour = Math.floor(minutes / 60)
      const minute = minutes % 60
      const time = `${hour}:${String(minute).padStart(2, "0")}`
      return {
        index,
        price,
        label: time,
        tick: minute === 0 ? `${hour}:00` : "",
      }
    }
    if (range === "1W") {
      const day = week[Math.floor(index / 7)] ?? END
      const weekday = WEEKDAYS[day.getDay()] ?? ""
      return {
        index,
        price,
        label: `${weekday} ${10 + (index % 7)}:00`,
        tick: index % 7 === 0 ? weekday : "",
      }
    }
    if (range === "1M" || range === "3M") {
      const label = shortDay(days[index] ?? END)
      return { index, price, label, tick: label }
    }
    if (range === "1Y") {
      const day = new Date(END)
      day.setDate(day.getDate() - (points - 1 - index) * 7)
      return {
        index,
        price,
        label: `${shortDay(day)}, ${day.getFullYear()}`,
        tick: shortMonth(day),
      }
    }
    const month = new Date(
      END.getFullYear(),
      END.getMonth() - (points - 1 - index),
      1
    )
    return {
      index,
      price,
      label: `${MONTHS[month.getMonth()]} ${month.getFullYear()}`,
      tick: String(month.getFullYear()),
    }
  })
}

function resample(source: Point[]) {
  const samples: Point[] = []
  let previous = -1
  for (let index = 0; index < SAMPLES; index++) {
    const position = (index * (source.length - 1)) / (SAMPLES - 1)
    const from = Math.floor(position)
    const to = Math.min(source.length - 1, from + 1)
    const nearest = Math.round(position)
    const start = source[from]
    const end = source[to]
    const closest = source[nearest]
    if (!start || !end || !closest) return samples
    const price = start.price + (end.price - start.price) * (position - from)
    samples.push({
      index,
      price: Number(price.toFixed(2)),
      label: closest.label,
      tick: nearest !== previous ? closest.tick : "",
    })
    previous = nearest
  }
  return samples
}

function tickIndexes(points: Point[], max: number) {
  const ticks = points
    .filter(
      (point, index) => point.tick && point.tick !== points[index - 1]?.tick
    )
    .map((point) => point.index)
  if (ticks.length <= max) return ticks
  const step = Math.ceil(ticks.length / max)
  return ticks.filter((_, index) => index % step === 0)
}

export function AreaChartInteractive() {
  const [range, setRange] = React.useState<Range>("1M")
  const [active, setActive] = React.useState<number | null>(null)
  const points = React.useMemo(() => resample(generate(range)), [range])

  const opening = points[0]
  const current = points[active ?? points.length - 1]
  if (!opening || !current) return null

  const first = opening.price
  const change = current.price - first
  const rising = change >= 0
  const prices = points.map((point) => point.price)
  const min = Math.min(...prices)
  const max = Math.max(...prices)
  const padding = (max - min) * 0.12
  const color = rising ? "green-500" : "destructive"
  const chartConfig = {
    price: { label: "Price", color },
  } satisfies ChartConfig

  const stats = [
    ["Open", formatPrice(first)],
    ["High", formatPrice(max)],
    ["Low", formatPrice(min)],
    ["Volume", range === "1D" ? "41.2M" : "1.24B"],
  ]

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View className="min-w-56 grow gap-0.5">
          <View className="flex-row items-baseline gap-2">
            <Text className="text-2xl font-semibold tracking-tight">ACME</Text>
            <Text className="text-base text-muted-foreground">Acme Corp.</Text>
          </View>
          <View className="flex-row flex-wrap items-baseline gap-2.5">
            <Text className="text-3xl font-semibold tracking-tight tabular-nums">
              ${formatPrice(current.price)}
            </Text>
            <Text
              className={cn(
                "text-base font-semibold tabular-nums",
                rising
                  ? "text-green-600 dark:text-green-400"
                  : "text-destructive"
              )}
            >
              {formatPrice(change, true)} (
              {formatPrice(Math.abs((change / first) * 100))}%)
            </Text>
          </View>
          <Text className="min-h-5 text-sm text-muted-foreground">
            {active === null ? RANGES[range].caption : current.label}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[range]}
          onValueChange={(value) => {
            if (value[0]) setRange(value[0] as Range)
          }}
          accessibilityLabel="Time range"
        >
          {(Object.keys(RANGES) as Range[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm">
              <Text>{key}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-4">
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="ACME price"
          className="h-72 w-full"
        >
          <AreaChart
            data={points}
            margin={{ top: 10, right: 0, left: 0, bottom: 0 }}
            onActiveIndexChange={setActive}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="index"
              type="number"
              domain={["dataMin", "dataMax"]}
              ticks={tickIndexes(points, 6)}
              tickFormatter={(index: number) => points[index]?.tick ?? ""}
              tickMargin={8}
              minTickGap={4}
            />
            <YAxis
              orientation="right"
              domain={[min - padding, max + padding]}
              tickFormatter={(value: number) => Math.round(value).toString()}
              tickMargin={6}
              tickCount={5}
              width={40}
            />
            <ReferenceLine
              y={first}
              stroke="muted-foreground"
              strokeDasharray="2 3"
            />
            <ChartTooltip
              content={() => null}
              cursor={{ stroke: "muted-foreground", strokeWidth: 1 }}
            />
            <Area
              isAnimationActive={false}
              dataKey="price"
              type="linear"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.3 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              activeDot={{
                r: 5,
                fill: color,
                stroke: "muted",
                strokeWidth: 2,
              }}
            />
          </AreaChart>
        </ChartContainer>
        <View className="flex-row flex-wrap gap-x-6">
          {stats.map(([term, value]) => (
            <View
              key={term}
              className="min-w-36 grow basis-0 flex-row items-center gap-2 border-b border-border py-[0.4375rem]"
            >
              <Text className="grow text-sm text-muted-foreground">{term}</Text>
              <Text className="text-sm font-semibold tabular-nums">
                {value}
              </Text>
            </View>
          ))}
        </View>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text), [Toggle Group](https://suiss.app/ui/docs/components/toggle-group).

2. Copy and paste the following code into `components/charts/area-chart-interactive.tsx`:

```tsx title="stylesheet/components/charts/area-chart-interactive.tsx"
import * as React from "react"
import { StyleSheet, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, palette, useTheme } from "@/components/ui/theme"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Range = "1D" | "1W" | "1M" | "3M" | "1Y" | "5Y"

type Point = { index: number; price: number; label: string; tick: string }

const RANGES: Record<
  Range,
  {
    points: number
    seed: number
    volatility: number
    drift: number
    caption: string
  }
> = {
  "1D": {
    points: 78,
    seed: 11,
    volatility: 0.0025,
    drift: 0.46,
    caption: "Today",
  },
  "1W": {
    points: 35,
    seed: 23,
    volatility: 0.004,
    drift: 0.46,
    caption: "Past week",
  },
  "1M": {
    points: 22,
    seed: 37,
    volatility: 0.012,
    drift: 0.53,
    caption: "Past month",
  },
  "3M": {
    points: 64,
    seed: 41,
    volatility: 0.014,
    drift: 0.46,
    caption: "Past 3 months",
  },
  "1Y": {
    points: 52,
    seed: 59,
    volatility: 0.03,
    drift: 0.46,
    caption: "Past year",
  },
  "5Y": {
    points: 60,
    seed: 73,
    volatility: 0.045,
    drift: 0.46,
    caption: "Past 5 years",
  },
}

const LAST_PRICE = 254.32
const END = new Date(2026, 9, 6)
const SAMPLES = 80

const MONTHS = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
]

const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

function shortMonth(date: Date) {
  return (MONTHS[date.getMonth()] ?? "").slice(0, 3)
}

function shortDay(date: Date) {
  return `${shortMonth(date)} ${date.getDate()}`
}

const styles = StyleSheet.create({
  header: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "flex-start",
    justifyContent: "space-between",
    gap: 16,
  },
  heading: { minWidth: 224, flexGrow: 1, gap: 2 },
  ticker: { flexDirection: "row", alignItems: "baseline", gap: 8 },
  symbol: { ...fontSize["2xl"], fontWeight: "600", letterSpacing: -0.6 },
  company: { ...fontSize.base },
  quote: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "baseline",
    gap: 10,
  },
  price: {
    ...fontSize["3xl"],
    fontWeight: "600",
    letterSpacing: -0.75,
    fontVariant: ["tabular-nums"],
  },
  change: {
    ...fontSize.base,
    fontWeight: "600",
    fontVariant: ["tabular-nums"],
  },
  caption: { ...fontSize.sm, minHeight: 20 },
  content: { gap: 16 },
  chart: { height: 288 },
  stats: { flexDirection: "row", flexWrap: "wrap", columnGap: 24 },
  stat: {
    minWidth: 144,
    flexGrow: 1,
    flexBasis: 0,
    flexDirection: "row",
    alignItems: "center",
    gap: 8,
    borderBottomWidth: 1,
    paddingVertical: 7,
  },
  term: { ...fontSize.sm, flexGrow: 1 },
  amount: { ...fontSize.sm, fontWeight: "600", fontVariant: ["tabular-nums"] },
})

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function businessDays(count: number) {
  const days: Date[] = []
  const day = new Date(END)
  while (days.length < count) {
    if (day.getDay() % 6) days.unshift(new Date(day))
    day.setDate(day.getDate() - 1)
  }
  return days
}

function generate(range: Range): Point[] {
  const { points, seed, volatility, drift } = RANGES[range]
  let state = seed
  let value = 100
  const values = Array.from({ length: points }, () => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - drift) * volatility
    return value
  })
  const last = values.at(-1)
  if (last === undefined) return []
  const scale = LAST_PRICE / last
  const days = businessDays(points)
  const week = businessDays(5)

  return values.map((raw, index) => {
    const price = Number((raw * scale).toFixed(2))
    if (range === "1D") {
      const minutes = 570 + index * 5
      const hour = Math.floor(minutes / 60)
      const minute = minutes % 60
      const time = `${hour}:${String(minute).padStart(2, "0")}`
      return {
        index,
        price,
        label: time,
        tick: minute === 0 ? `${hour}:00` : "",
      }
    }
    if (range === "1W") {
      const day = week[Math.floor(index / 7)] ?? END
      const weekday = WEEKDAYS[day.getDay()] ?? ""
      return {
        index,
        price,
        label: `${weekday} ${10 + (index % 7)}:00`,
        tick: index % 7 === 0 ? weekday : "",
      }
    }
    if (range === "1M" || range === "3M") {
      const label = shortDay(days[index] ?? END)
      return { index, price, label, tick: label }
    }
    if (range === "1Y") {
      const day = new Date(END)
      day.setDate(day.getDate() - (points - 1 - index) * 7)
      return {
        index,
        price,
        label: `${shortDay(day)}, ${day.getFullYear()}`,
        tick: shortMonth(day),
      }
    }
    const month = new Date(
      END.getFullYear(),
      END.getMonth() - (points - 1 - index),
      1
    )
    return {
      index,
      price,
      label: `${MONTHS[month.getMonth()]} ${month.getFullYear()}`,
      tick: String(month.getFullYear()),
    }
  })
}

function resample(source: Point[]) {
  const samples: Point[] = []
  let previous = -1
  for (let index = 0; index < SAMPLES; index++) {
    const position = (index * (source.length - 1)) / (SAMPLES - 1)
    const from = Math.floor(position)
    const to = Math.min(source.length - 1, from + 1)
    const nearest = Math.round(position)
    const start = source[from]
    const end = source[to]
    const closest = source[nearest]
    if (!start || !end || !closest) return samples
    const price = start.price + (end.price - start.price) * (position - from)
    samples.push({
      index,
      price: Number(price.toFixed(2)),
      label: closest.label,
      tick: nearest !== previous ? closest.tick : "",
    })
    previous = nearest
  }
  return samples
}

function tickIndexes(points: Point[], max: number) {
  const ticks = points
    .filter(
      (point, index) => point.tick && point.tick !== points[index - 1]?.tick
    )
    .map((point) => point.index)
  if (ticks.length <= max) return ticks
  const step = Math.ceil(ticks.length / max)
  return ticks.filter((_, index) => index % step === 0)
}

export function AreaChartInteractive() {
  const { colors, isDark } = useTheme()
  const success = isDark ? palette.green400 : palette.green600
  const [range, setRange] = React.useState<Range>("1M")
  const [active, setActive] = React.useState<number | null>(null)
  const points = React.useMemo(() => resample(generate(range)), [range])

  const opening = points[0]
  const current = points[active ?? points.length - 1]
  if (!opening || !current) return null

  const first = opening.price
  const change = current.price - first
  const rising = change >= 0
  const prices = points.map((point) => point.price)
  const min = Math.min(...prices)
  const max = Math.max(...prices)
  const padding = (max - min) * 0.12
  const color = rising ? "green-500" : "destructive"
  const chartConfig = {
    price: { label: "Price", color },
  } satisfies ChartConfig

  const stats = [
    ["Open", formatPrice(first)],
    ["High", formatPrice(max)],
    ["Low", formatPrice(min)],
    ["Volume", range === "1D" ? "41.2M" : "1.24B"],
  ]

  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <View style={styles.heading}>
          <View style={styles.ticker}>
            <Text style={styles.symbol}>ACME</Text>
            <Text style={[styles.company, { color: colors.mutedForeground }]}>
              Acme Corp.
            </Text>
          </View>
          <View style={styles.quote}>
            <Text style={styles.price}>${formatPrice(current.price)}</Text>
            <Text
              style={[
                styles.change,
                {
                  color: rising ? success : colors.destructive,
                },
              ]}
            >
              {formatPrice(change, true)} (
              {formatPrice(Math.abs((change / first) * 100))}%)
            </Text>
          </View>
          <Text style={[styles.caption, { color: colors.mutedForeground }]}>
            {active === null ? RANGES[range].caption : current.label}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[range]}
          onValueChange={(value) => {
            if (value[0]) setRange(value[0] as Range)
          }}
          accessibilityLabel="Time range"
        >
          {(Object.keys(RANGES) as Range[]).map((key) => (
            <ToggleGroupItem key={key} value={key} size="sm">
              <Text>{key}</Text>
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </CardHeader>
      <CardContent style={styles.content}>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="ACME price"
          style={styles.chart}
        >
          <AreaChart
            data={points}
            margin={{ top: 10, right: 0, left: 0, bottom: 0 }}
            onActiveIndexChange={setActive}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="index"
              type="number"
              domain={["dataMin", "dataMax"]}
              ticks={tickIndexes(points, 6)}
              tickFormatter={(index: number) => points[index]?.tick ?? ""}
              tickMargin={8}
              minTickGap={4}
            />
            <YAxis
              orientation="right"
              domain={[min - padding, max + padding]}
              tickFormatter={(value: number) => Math.round(value).toString()}
              tickMargin={6}
              tickCount={5}
              width={40}
            />
            <ReferenceLine
              y={first}
              stroke="muted-foreground"
              strokeDasharray="2 3"
            />
            <ChartTooltip
              content={() => null}
              cursor={{ stroke: "muted-foreground", strokeWidth: 1 }}
            />
            <Area
              isAnimationActive={false}
              dataKey="price"
              type="linear"
              strokeWidth={2}
              fill={{
                stops: [
                  { offset: 0, opacity: 0.3 },
                  { offset: 1, opacity: 0.02 },
                ],
              }}
              activeDot={{
                r: 5,
                fill: color,
                stroke: "muted",
                strokeWidth: 2,
              }}
            />
          </AreaChart>
        </ChartContainer>
        <View style={styles.stats}>
          {stats.map(([term, value]) => (
            <View
              key={term}
              style={[styles.stat, { borderColor: colors.border }]}
            >
              <Text style={[styles.term, { color: colors.mutedForeground }]}>
                {term}
              </Text>
              <Text style={styles.amount}>{value}</Text>
            </View>
          ))}
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Add the Swift package to your app:

```swift title="Package.swift"
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
```

3. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

4. Copy the source and every file it uses:

- `swift/Charts/AreaChartInteractive.swift`: shown above

- `swift/Components/Button.swift`: see [Button](https://suiss.app/ui/docs/components/button.md)

- `swift/Components/ButtonGroup.swift`: see [Button Group](https://suiss.app/ui/docs/components/button-group.md)

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Checkbox.swift`: see [Checkbox](https://suiss.app/ui/docs/components/checkbox.md)

- `swift/Components/Field.swift`: see [Field](https://suiss.app/ui/docs/components/field.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

- `swift/Components/Toggle.swift`: see [Toggle](https://suiss.app/ui/docs/components/toggle.md)

- `swift/Components/ToggleGroup.swift`: see [Toggle Group](https://suiss.app/ui/docs/components/toggle-group.md)

5. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartInteractive.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Checkbox.kt`: see [Checkbox](https://suiss.app/ui/docs/components/checkbox.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/Field.kt`: see [Field](https://suiss.app/ui/docs/components/field.md)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

- `kotlin/components/Label.kt`: see [Label](https://suiss.app/ui/docs/components/label.md)

- `kotlin/components/Separator.kt`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

- `kotlin/components/Toggle.kt`: see [Toggle](https://suiss.app/ui/docs/components/toggle.md)

- `kotlin/components/ToggleGroup.kt`: see [Toggle Group](https://suiss.app/ui/docs/components/toggle-group.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartInteractive } from "@/components/charts/area-chart-interactive"
```

```tsx
<AreaChartInteractive />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaInteractiveExample: View {
  var body: some View {
    AreaChartInteractive()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartInteractive

@Composable
fun AreaInteractiveExample() {
    AreaChartInteractive()
}
```



## Area Chart Linear

A single filled area whose points are joined by straight segments instead of a smoothed curve.

Source: https://suiss.app/ui/docs/charts/area-chart#linear

**React**

**Example**

```tsx title="components/charts/area-chart-linear.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartLinear() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Linear</CardTitle>
        <CardDescription>Points joined by straight lines</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="linear"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

One series filled under straight line segments instead of a smoothed curve. Prefer it to the default when smoothing would suggest values between points that were never measured.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-linear
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-linear
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-linear.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartLinear() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Linear</CardTitle>
        <CardDescription>Points joined by straight lines</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="linear"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartLinear } from "@/components/charts/area-chart-linear"
```

```tsx
<AreaChartLinear />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-linear.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartLinear() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Linear</CardTitle>
        <CardDescription>Points joined by straight lines</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Linear"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="linear"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartLinear.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
]

public struct AreaChartLinear: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Linear", description: "Points joined by straight lines")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                AreaMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.linear)
                  .foregroundStyle(chartConfig.color("desktop").opacity(0.18))
                LineMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.linear)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(chartConfig.color("desktop"))
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
              if let selection {
                PointMark(x: .value("Month", selection), y: .value("Desktop", chartData[selection].desktop))
                  .symbolSize(64)
                  .foregroundStyle(chartConfig.color("desktop"))
              }
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Linear",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload, indicator: .line)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartLinear.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator

private class AreaLinearRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaLinearRow("January", 186.0, 80.0),
    AreaLinearRow("February", 305.0, 200.0),
    AreaLinearRow("March", 237.0, 120.0),
    AreaLinearRow("April", 173.0, 190.0),
    AreaLinearRow("May", 209.0, 130.0),
    AreaLinearRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
)

@Composable
fun AreaChartLinear(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Linear", description = "Points joined by straight lines")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 12.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Linear",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip { ChartTooltipContent(indicator = ChartTooltipIndicator.Line) }
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Linear,
                        strokeWidth = 2.dp,
                        fill = ChartFill.Solid(alpha = 0.18f),
                    )
                }
            }
        }
    }
}
```

**React Native**

The same one-series area as the default chart, with `type="linear"` so each month connects to the next with a straight segment. It has a month axis, a dashed grid and a tooltip with a line indicator.

Replace `chartData` with your records and change each `dataKey` to match your fields. Set the label and color of the series in `chartConfig`. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-linear
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-linear
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-linear
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-linear --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-linear
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-linear --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-linear.tsx`:

- `uniwind/components/charts/area-chart-linear.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-linear.tsx`:

```tsx title="nativewind/components/charts/area-chart-linear.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartLinear() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Linear</CardTitle>
        <CardDescription>Points joined by straight lines</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Linear"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="linear"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-linear.tsx`:

```tsx title="stylesheet/components/charts/area-chart-linear.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartLinear() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Linear</CardTitle>
        <CardDescription>Points joined by straight lines</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Linear"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="linear"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartLinear.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartLinear.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartLinear } from "@/components/charts/area-chart-linear"
```

```tsx
<AreaChartLinear />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaLinearExample: View {
  var body: some View {
    AreaChartLinear()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartLinear

@Composable
fun AreaLinearExample() {
    AreaChartLinear()
}
```



## Area Chart Range

A heart-rate band showing each hour's low-to-high range as a shaded area with an average line through it.

Source: https://suiss.app/ui/docs/charts/area-chart#range

**React**

**Example**

```tsx title="components/charts/area-chart-range.tsx"
"use client"

import {
  Area,
  CartesianGrid,
  ComposedChart,
  Line,
  XAxis,
  YAxis,
} from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const readings: [low: number, high: number, average: number][] = [
  [48, 62, 54],
  [46, 60, 52],
  [47, 64, 54],
  [45, 61, 52],
  [48, 63, 55],
  [46, 66, 54],
  [56, 78, 64],
  [58, 82, 66],
  [64, 88, 74],
  [66, 90, 76],
  [64, 92, 74],
  [66, 89, 75],
  [65, 94, 76],
  [66, 90, 75],
  [64, 88, 74],
  [65, 91, 76],
  [66, 92, 75],
  [68, 96, 78],
  [104, 158, 126],
  [102, 150, 122],
  [70, 94, 78],
  [66, 90, 74],
  [60, 82, 68],
  [52, 70, 58],
]

const chartData = readings.map(([low, high, average], hour) => ({
  hour: `${hour}:00`,
  range: [low, high] as const,
  average,
}))

const chartConfig = {
  range: { label: "Range", color: "var(--color-red-500)" },
  average: { label: "Average", color: "var(--color-red-500)" },
} satisfies ChartConfig

const low = Math.min(...chartData.map((point) => point.range[0]))
const high = Math.max(...chartData.map((point) => point.range[1]))

export function AreaChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-destructive">Heart rate</p>
        <p className="flex items-baseline gap-1">
          <span className="text-3xl font-semibold tracking-tight tabular-nums">
            {low}–{high}
          </span>
          <span className="text-base font-semibold text-muted-foreground">
            BPM
          </span>
        </p>
        <p className="text-sm text-muted-foreground">Today</p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full"
        >
          <ComposedChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 16, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={5}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              domain={[40, 170]}
              ticks={[50, 100, 150]}
            />
            <ChartTooltip
              content={
                <ChartTooltipContent
                  indicator="line"
                  formatter={(value, name) => (
                    <div className="flex w-full justify-between gap-3">
                      <span className="text-muted-foreground">
                        {chartConfig[name as keyof typeof chartConfig].label}
                      </span>
                      <span className="font-semibold tabular-nums">
                        {Array.isArray(value) ? value.join("–") : value} BPM
                      </span>
                    </div>
                  )}
                />
              }
            />
            <Area
              dataKey="range"
              type="monotone"
              stroke="none"
              fill="var(--color-range)"
              fillOpacity={0.22}
            />
            <Line
              dataKey="average"
              type="monotone"
              stroke="var(--color-average)"
              strokeWidth={2}
              dot={false}
            />
          </ComposedChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A health-style heart-rate card that shades each hour's low-to-high range and draws the average as a line through the band. Use it for any metric where the spread matters as much as the typical value, such as temperatures or response times.

Give each record a two-number `range` array and an `average`; the header's overall low and high come from the data. The value axis has a fixed `domain`, so widen it and its `ticks` if readings fall outside it, and change the unit text in the tooltip and header. Set both colors in `chartConfig`. Focus the chart and use the arrow keys to move the tooltip between hours.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-range
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-range
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-range.tsx"
"use client"

import {
  Area,
  CartesianGrid,
  ComposedChart,
  Line,
  XAxis,
  YAxis,
} from "recharts"

import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const readings: [low: number, high: number, average: number][] = [
  [48, 62, 54],
  [46, 60, 52],
  [47, 64, 54],
  [45, 61, 52],
  [48, 63, 55],
  [46, 66, 54],
  [56, 78, 64],
  [58, 82, 66],
  [64, 88, 74],
  [66, 90, 76],
  [64, 92, 74],
  [66, 89, 75],
  [65, 94, 76],
  [66, 90, 75],
  [64, 88, 74],
  [65, 91, 76],
  [66, 92, 75],
  [68, 96, 78],
  [104, 158, 126],
  [102, 150, 122],
  [70, 94, 78],
  [66, 90, 74],
  [60, 82, 68],
  [52, 70, 58],
]

const chartData = readings.map(([low, high, average], hour) => ({
  hour: `${hour}:00`,
  range: [low, high] as const,
  average,
}))

const chartConfig = {
  range: { label: "Range", color: "var(--color-red-500)" },
  average: { label: "Average", color: "var(--color-red-500)" },
} satisfies ChartConfig

const low = Math.min(...chartData.map((point) => point.range[0]))
const high = Math.max(...chartData.map((point) => point.range[1]))

export function AreaChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-destructive">Heart rate</p>
        <p className="flex items-baseline gap-1">
          <span className="text-3xl font-semibold tracking-tight tabular-nums">
            {low}–{high}
          </span>
          <span className="text-base font-semibold text-muted-foreground">
            BPM
          </span>
        </p>
        <p className="text-sm text-muted-foreground">Today</p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full"
        >
          <ComposedChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 16, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={5}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              domain={[40, 170]}
              ticks={[50, 100, 150]}
            />
            <ChartTooltip
              content={
                <ChartTooltipContent
                  indicator="line"
                  formatter={(value, name) => (
                    <div className="flex w-full justify-between gap-3">
                      <span className="text-muted-foreground">
                        {chartConfig[name as keyof typeof chartConfig].label}
                      </span>
                      <span className="font-semibold tabular-nums">
                        {Array.isArray(value) ? value.join("–") : value} BPM
                      </span>
                    </div>
                  )}
                />
              }
            />
            <Area
              dataKey="range"
              type="monotone"
              stroke="none"
              fill="var(--color-range)"
              fillOpacity={0.22}
            />
            <Line
              dataKey="average"
              type="monotone"
              stroke="var(--color-average)"
              strokeWidth={2}
              dot={false}
            />
          </ComposedChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartRange } from "@/components/charts/area-chart-range"
```

```tsx
<AreaChartRange />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-range.tsx"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ComposedChart,
  Line,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const readings: [low: number, high: number, average: number][] = [
  [48, 62, 54],
  [46, 60, 52],
  [47, 64, 54],
  [45, 61, 52],
  [48, 63, 55],
  [46, 66, 54],
  [56, 78, 64],
  [58, 82, 66],
  [64, 88, 74],
  [66, 90, 76],
  [64, 92, 74],
  [66, 89, 75],
  [65, 94, 76],
  [66, 90, 75],
  [64, 88, 74],
  [65, 91, 76],
  [66, 92, 75],
  [68, 96, 78],
  [104, 158, 126],
  [102, 150, 122],
  [70, 94, 78],
  [66, 90, 74],
  [60, 82, 68],
  [52, 70, 58],
]

const chartData = readings.map(([low, high, average], hour) => ({
  hour: `${hour}:00`,
  range: [low, high] as const,
  average,
}))

const chartConfig = {
  range: { label: "Range", color: "red-500" },
  average: { label: "Average", color: "red-500" },
} satisfies ChartConfig

const low = Math.min(...chartData.map((point) => point.range[0]))
const high = Math.max(...chartData.map((point) => point.range[1]))

export function AreaChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-destructive">
          Heart rate
        </Text>
        <View className="flex-row items-baseline gap-1">
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {low}–{high}
          </Text>
          <Text className="text-base font-semibold text-muted-foreground">
            BPM
          </Text>
        </View>
        <Text className="text-sm text-muted-foreground">Today</Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Heart rate"
          className="h-40 w-full"
        >
          <ComposedChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 16, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis dataKey="hour" tickMargin={8} interval={5} />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              domain={[40, 170]}
              ticks={[50, 100, 150]}
            />
            <ChartTooltip
              content={
                <ChartTooltipContent
                  indicator="line"
                  formatter={(value, name) => (
                    <View className="w-full flex-row justify-between gap-3">
                      <Text className="text-muted-foreground">
                        {chartConfig[name as keyof typeof chartConfig].label}
                      </Text>
                      <Text className="font-semibold tabular-nums">
                        {typeof value === "number" ? value : value.join("–")}{" "}
                        BPM
                      </Text>
                    </View>
                  )}
                />
              }
            />
            <Area
              dataKey="range"
              type="monotone"
              stroke="none"
              fillOpacity={0.22}
            />
            <Line dataKey="average" type="monotone" strokeWidth={2} />
          </ComposedChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartRange.swift"
import Charts
import SwiftUI

private let readings: [(low: Double, high: Double, average: Double)] = [
  (48, 62, 54), (46, 60, 52), (47, 64, 54), (45, 61, 52), (48, 63, 55), (46, 66, 54),
  (56, 78, 64), (58, 82, 66), (64, 88, 74), (66, 90, 76), (64, 92, 74), (66, 89, 75),
  (65, 94, 76), (66, 90, 75), (64, 88, 74), (65, 91, 76), (66, 92, 75), (68, 96, 78),
  (104, 158, 126), (102, 150, 122), (70, 94, 78), (66, 90, 74), (60, 82, 68), (52, 70, 58),
]

private let hours = readings.indices.map { "\($0):00" }

private let chartConfig: ChartConfig = [
  "range": .init("Range", color: Palette.red500),
  "average": .init("Average", color: Palette.red500),
]

private let low = Int(readings.map(\.low).min() ?? 0)
private let high = Int(readings.map(\.high).max() ?? 0)

public struct AreaChartRange: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      VStack(alignment: .leading, spacing: 2) {
        Text("Heart rate")
          .textStyle(.sm, weight: .semibold)
          .foregroundStyle(EsuissColor.destructive)
        HStack(alignment: .firstTextBaseline, spacing: 4) {
          Text(verbatim: "\(low)–\(high)")
            .textStyle(.xl3, weight: .semibold)
            .monospacedDigit()
          Text("BPM")
            .textStyle(.base, weight: .semibold)
            .foregroundStyle(EsuissColor.mutedForeground)
        }
        Text("Today")
          .textStyle(.sm)
          .foregroundStyle(EsuissColor.mutedForeground)
      }
      .padding(.horizontal, 16)
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(readings.indices, id: \.self) { index in
                AreaMark(x: .value("Hour", index), yStart: .value("Low", readings[index].low), yEnd: .value("High", readings[index].high))
                  .interpolationMethod(.monotone)
                  .foregroundStyle(chartConfig.color("range").opacity(0.22))
                LineMark(x: .value("Hour", index), y: .value("Average", readings[index].average))
                  .interpolationMethod(.monotone)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(chartConfig.color("average"))
              }
              .chartReveal(progress, x: 0...(readings.count - 1))
              if let selection {
                PointMark(x: .value("Hour", selection), y: .value("Average", readings[selection].average))
                  .symbolSize(64)
                  .foregroundStyle(chartConfig.color("average"))
              }
            }
            .chartXScale(domain: 0...(readings.count - 1), range: .plotDimension(padding: 16))
            .chartYScale(domain: 40...170)
            .chartXAxis { ChartAxis.x(values: [0, 6, 12, 18]) { hours[$0] } }
            .chartYAxis { ChartAxis.y(values: [50.0, 100, 150]) { "\(Int($0))" } }
            .chartTooltip(
              x: Array(readings.indices),
              labels: hours,
              selection: $selection,
              accessibilityLabel: "Heart rate",
              items: { index in
                [
                  ChartTooltipItem("range", value: readings[index].high),
                  ChartTooltipItem("average", value: readings[index].average),
                ]
              }
            ) { payload in
              ChartTooltipContent(payload, indicator: .line) { item in
                Text(LocalizedStringKey(chartConfig.label(item.key)))
                  .foregroundStyle(EsuissColor.mutedForeground)
                Spacer(minLength: 12)
                Text(verbatim: item.key == "range"
                  ? "\(Int(readings[payload.index].low))–\(Int(readings[payload.index].high)) BPM"
                  : "\(Int(item.value)) BPM")
                  .scaledFont(TextStyle.xs, weight: .semibold)
                  .monospacedDigit()
              }
            }
          }
        }
        .frame(height: 160)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartRange.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartAxisOrientation
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator
import com.esuiss.ui.components.ComposedChart
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Typography

private class HeartRateRow(val hour: String, val low: Int, val high: Int, val average: Int)

private val readings = listOf(
    Triple(48, 62, 54), Triple(46, 60, 52), Triple(47, 64, 54), Triple(45, 61, 52),
    Triple(48, 63, 55), Triple(46, 66, 54), Triple(56, 78, 64), Triple(58, 82, 66),
    Triple(64, 88, 74), Triple(66, 90, 76), Triple(64, 92, 74), Triple(66, 89, 75),
    Triple(65, 94, 76), Triple(66, 90, 75), Triple(64, 88, 74), Triple(65, 91, 76),
    Triple(66, 92, 75), Triple(68, 96, 78), Triple(104, 158, 126), Triple(102, 150, 122),
    Triple(70, 94, 78), Triple(66, 90, 74), Triple(60, 82, 68), Triple(52, 70, 58),
)

private val chartData = readings.mapIndexed { hour, (low, high, average) -> HeartRateRow("$hour:00", low, high, average) }

private val chartConfig = ChartConfig(
    "range" to ChartConfigItem("Range") { Palette.red500 },
    "average" to ChartConfigItem("Average") { Palette.red500 },
)

private val low = chartData.minOf { it.low }

private val high = chartData.maxOf { it.high }

@Composable
fun AreaChartRange(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    val value = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum")
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
                BasicText("Heart rate", style = Typography.sm.copy(color = colors.destructive, fontWeight = FontWeight.SemiBold))
                Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
                    BasicText(
                        "$low–$high",
                        Modifier.alignByBaseline(),
                        style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                    )
                    BasicText(
                        "BPM",
                        Modifier.alignByBaseline(),
                        style = Typography.base.copy(color = colors.mutedForeground, fontWeight = FontWeight.SemiBold),
                    )
                }
                BasicText("Today", style = Typography.sm.copy(color = colors.mutedForeground))
            }
        }
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(160.dp),
            ) {
                ComposedChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 16.dp),
                    accessibilityLabel = "Heart rate",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.hour }, tickMargin = 8.dp, interval = 5)
                    YAxis(
                        orientation = ChartAxisOrientation.Right,
                        tickMargin = 6.dp,
                        domain = 40.0..170.0,
                        ticks = listOf(50.0, 100.0, 150.0),
                        tickFormatter = { it.toInt().toString() },
                    )
                    ChartTooltip {
                        ChartTooltipContent(
                            indicator = ChartTooltipIndicator.Line,
                            formatter = { item ->
                                Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
                                    BasicText(
                                        chartConfig[item.key]?.label ?: item.key,
                                        style = Typography.xs.copy(color = colors.mutedForeground),
                                    )
                                    BasicText(
                                        if (item.base != null) "${item.base.toInt()}–${item.value.toInt()} BPM" else "${item.value.toInt()} BPM",
                                        style = value,
                                    )
                                }
                            },
                        )
                    }
                    Area(
                        "range",
                        value = { it.high.toDouble() },
                        base = { it.low.toDouble() },
                        curve = ChartCurve.Monotone,
                        strokeWidth = 0.dp,
                        fill = ChartFill.Solid(alpha = 0.22f),
                    )
                    Line("average", value = { it.average.toDouble() }, curve = ChartCurve.Monotone, strokeWidth = 2.dp)
                }
            }
        }
    }
}
```

**React Native**

A `ComposedChart` that pairs a range `Area`, filled between each hour's low and high reading, with a `Line` for the hourly average. The header shows the day's lowest and highest values in BPM, and the tooltip formats both the range and the average with a custom row built from `Text`.

Replace the `readings` array with `[low, high, average]` tuples for each hour; the header range and the chart data are derived from it. Adjust the `YAxis` `domain` and `ticks` to fit your values. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-range
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-range
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-range
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-range --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-range
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-range --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/area-chart-range.tsx`:

- `uniwind/components/charts/area-chart-range.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/area-chart-range.tsx`:

```tsx title="nativewind/components/charts/area-chart-range.tsx"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ComposedChart,
  Line,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const readings: [low: number, high: number, average: number][] = [
  [48, 62, 54],
  [46, 60, 52],
  [47, 64, 54],
  [45, 61, 52],
  [48, 63, 55],
  [46, 66, 54],
  [56, 78, 64],
  [58, 82, 66],
  [64, 88, 74],
  [66, 90, 76],
  [64, 92, 74],
  [66, 89, 75],
  [65, 94, 76],
  [66, 90, 75],
  [64, 88, 74],
  [65, 91, 76],
  [66, 92, 75],
  [68, 96, 78],
  [104, 158, 126],
  [102, 150, 122],
  [70, 94, 78],
  [66, 90, 74],
  [60, 82, 68],
  [52, 70, 58],
]

const chartData = readings.map(([low, high, average], hour) => ({
  hour: `${hour}:00`,
  range: [low, high] as const,
  average,
}))

const chartConfig = {
  range: { label: "Range", color: "red-500" },
  average: { label: "Average", color: "red-500" },
} satisfies ChartConfig

const low = Math.min(...chartData.map((point) => point.range[0]))
const high = Math.max(...chartData.map((point) => point.range[1]))

export function AreaChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-destructive">
          Heart rate
        </Text>
        <View className="flex-row items-baseline gap-1">
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {low}–{high}
          </Text>
          <Text className="text-base font-semibold text-muted-foreground">
            BPM
          </Text>
        </View>
        <Text className="text-sm text-muted-foreground">Today</Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Heart rate"
          className="h-40 w-full"
        >
          <ComposedChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 16, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis dataKey="hour" tickMargin={8} interval={5} />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              domain={[40, 170]}
              ticks={[50, 100, 150]}
            />
            <ChartTooltip
              content={
                <ChartTooltipContent
                  indicator="line"
                  formatter={(value, name) => (
                    <View className="w-full flex-row justify-between gap-3">
                      <Text className="text-muted-foreground">
                        {chartConfig[name as keyof typeof chartConfig].label}
                      </Text>
                      <Text className="font-semibold tabular-nums">
                        {typeof value === "number" ? value : value.join("–")}{" "}
                        BPM
                      </Text>
                    </View>
                  )}
                />
              }
            />
            <Area
              dataKey="range"
              type="monotone"
              stroke="none"
              fillOpacity={0.22}
            />
            <Line dataKey="average" type="monotone" strokeWidth={2} />
          </ComposedChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/area-chart-range.tsx`:

```tsx title="stylesheet/components/charts/area-chart-range.tsx"
import { StyleSheet, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Area,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ComposedChart,
  Line,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

const readings: [low: number, high: number, average: number][] = [
  [48, 62, 54],
  [46, 60, 52],
  [47, 64, 54],
  [45, 61, 52],
  [48, 63, 55],
  [46, 66, 54],
  [56, 78, 64],
  [58, 82, 66],
  [64, 88, 74],
  [66, 90, 76],
  [64, 92, 74],
  [66, 89, 75],
  [65, 94, 76],
  [66, 90, 75],
  [64, 88, 74],
  [65, 91, 76],
  [66, 92, 75],
  [68, 96, 78],
  [104, 158, 126],
  [102, 150, 122],
  [70, 94, 78],
  [66, 90, 74],
  [60, 82, 68],
  [52, 70, 58],
]

const chartData = readings.map(([low, high, average], hour) => ({
  hour: `${hour}:00`,
  range: [low, high] as const,
  average,
}))

const chartConfig = {
  range: { label: "Range", color: "red-500" },
  average: { label: "Average", color: "red-500" },
} satisfies ChartConfig

const low = Math.min(...chartData.map((point) => point.range[0]))
const high = Math.max(...chartData.map((point) => point.range[1]))

const styles = StyleSheet.create({
  header: { gap: 2 },
  eyebrow: { ...fontSize.sm, fontWeight: "600" },
  reading: { flexDirection: "row", alignItems: "baseline", gap: 4 },
  value: {
    ...fontSize["3xl"],
    fontWeight: "600",
    letterSpacing: -0.75,
    fontVariant: ["tabular-nums"],
  },
  unit: { ...fontSize.base, fontWeight: "600" },
  caption: { ...fontSize.sm },
  chart: { height: 160 },
  row: {
    width: "100%",
    flexDirection: "row",
    justifyContent: "space-between",
    gap: 12,
  },
  strong: { fontWeight: "600", fontVariant: ["tabular-nums"] },
})

export function AreaChartRange() {
  const { colors } = useTheme()
  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <Text style={[styles.eyebrow, { color: colors.destructive }]}>
          Heart rate
        </Text>
        <View style={styles.reading}>
          <Text style={styles.value}>
            {low}–{high}
          </Text>
          <Text style={[styles.unit, { color: colors.mutedForeground }]}>
            BPM
          </Text>
        </View>
        <Text style={[styles.caption, { color: colors.mutedForeground }]}>
          Today
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Heart rate"
          style={styles.chart}
        >
          <ComposedChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 16, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis dataKey="hour" tickMargin={8} interval={5} />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              domain={[40, 170]}
              ticks={[50, 100, 150]}
            />
            <ChartTooltip
              content={
                <ChartTooltipContent
                  indicator="line"
                  formatter={(value, name) => (
                    <View style={styles.row}>
                      <Text style={{ color: colors.mutedForeground }}>
                        {chartConfig[name as keyof typeof chartConfig].label}
                      </Text>
                      <Text style={styles.strong}>
                        {typeof value === "number" ? value : value.join("–")}{" "}
                        BPM
                      </Text>
                    </View>
                  )}
                />
              }
            />
            <Area
              dataKey="range"
              type="monotone"
              stroke="none"
              fillOpacity={0.22}
            />
            <Line dataKey="average" type="monotone" strokeWidth={2} />
          </ComposedChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartRange.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartRange.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartRange } from "@/components/charts/area-chart-range"
```

```tsx
<AreaChartRange />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaRangeExample: View {
  var body: some View {
    AreaChartRange()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartRange

@Composable
fun AreaRangeExample() {
    AreaChartRange()
}
```



## Area Chart Sparkline

A watchlist with a tiny gradient area chart beside each price, colored by whether the stock is rising or falling.

Source: https://suiss.app/ui/docs/charts/area-chart#sparkline

**React**

**Example**

```tsx title="components/charts/area-chart-sparkline.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { type ChartConfig, ChartContainer } from "@/components/ui/chart"

const stocks = [
  { symbol: "ACME", name: "Acme Corp.", price: 254.32, change: 1.28, seed: 41 },
  { symbol: "GLBX", name: "Globex", price: 512.08, change: -0.64, seed: 52 },
  { symbol: "INIT", name: "Initech", price: 186.4, change: 2.91, seed: 63 },
  { symbol: "UMBR", name: "Umbrella", price: 438.15, change: -1.87, seed: 74 },
]

const chartConfig = {
  up: { label: "Rising", color: "var(--color-green-500)" },
  down: { label: "Falling", color: "var(--destructive)" },
} satisfies ChartConfig

const priceFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
})

const changeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
  signDisplay: "always",
})

function series(seed: number, rising: boolean) {
  let state = seed
  let value = 100
  return Array.from({ length: 30 }, (_, index) => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return { index, value }
  })
}

function Sparkline({ seed, rising }: { seed: number; rising: boolean }) {
  const key = rising ? "up" : "down"
  const id = React.useId()

  return (
    <ChartContainer
      config={chartConfig}
      aria-hidden
      className="aspect-auto h-8 w-18 shrink-0"
    >
      <AreaChart
        accessibilityLayer={false}
        data={series(seed, rising)}
        margin={{ top: 2, right: 0, left: 0, bottom: 2 }}
      >
        <defs>
          <linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
            <stop
              offset="0%"
              stopColor={`var(--color-${key})`}
              stopOpacity={0.25}
            />
            <stop
              offset="100%"
              stopColor={`var(--color-${key})`}
              stopOpacity={0.02}
            />
          </linearGradient>
        </defs>
        <YAxis hide domain={["dataMin", "dataMax"]} />
        <Area
          dataKey="value"
          type="linear"
          stroke={`var(--color-${key})`}
          strokeWidth={1.5}
          fill={`url(#${id})`}
          isAnimationActive={false}
          dot={false}
        />
      </AreaChart>
    </ChartContainer>
  )
}

export function AreaChartSparkline() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Watchlist</CardTitle>
        <CardDescription>Small area charts next to each price</CardDescription>
      </CardHeader>
      <CardContent>
        <ul className="flex flex-col">
          {stocks.map((stock) => {
            const rising = stock.change >= 0

            return (
              <li
                key={stock.symbol}
                className="flex items-center gap-3 border-border py-2.25 not-first:border-t"
              >
                <span className="flex min-w-0 flex-1 flex-col">
                  <span className="text-base font-semibold">
                    {stock.symbol}
                  </span>
                  <span className="truncate text-xs text-muted-foreground">
                    {stock.name}
                  </span>
                </span>
                <Sparkline seed={stock.seed} rising={rising} />
                <span className="flex flex-col items-end gap-0.75">
                  <span className="text-sm font-semibold tabular-nums">
                    {priceFormat.format(stock.price)}
                  </span>
                  <span
                    data-trend={rising ? "up" : "down"}
                    className="min-w-13 rounded-md px-1.5 py-0.5 text-end text-xs font-semibold text-primary-foreground tabular-nums data-[trend=down]:bg-destructive data-[trend=up]:bg-green-500 dark:text-background"
                  >
                    {changeFormat.format(stock.change)}%
                  </span>
                </span>
              </li>
            )
          })}
        </ul>
      </CardContent>
    </Card>
  )
}
```

A watchlist where each row pairs a stock's name and price with a tiny gradient area chart, tinted green when rising and red when falling. Use sparklines like these inside lists and tables where a full chart would be too much.

Replace the `stocks` array and the demo `series` generator with your own symbols and price history. The tint follows the sign of each row's `change`, with both colors in `chartConfig`, and the class names on `ChartContainer` set the size. Sparklines are hidden from assistive technology and have no tooltip or keyboard support, so keep the price and percentage text next to them. Animation is off so long lists render without motion.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-sparkline
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-sparkline
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-sparkline.tsx"
"use client"

import * as React from "react"
import { Area, AreaChart, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { type ChartConfig, ChartContainer } from "@/components/ui/chart"

const stocks = [
  { symbol: "ACME", name: "Acme Corp.", price: 254.32, change: 1.28, seed: 41 },
  { symbol: "GLBX", name: "Globex", price: 512.08, change: -0.64, seed: 52 },
  { symbol: "INIT", name: "Initech", price: 186.4, change: 2.91, seed: 63 },
  { symbol: "UMBR", name: "Umbrella", price: 438.15, change: -1.87, seed: 74 },
]

const chartConfig = {
  up: { label: "Rising", color: "var(--color-green-500)" },
  down: { label: "Falling", color: "var(--destructive)" },
} satisfies ChartConfig

const priceFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
})

const changeFormat = new Intl.NumberFormat("en-US", {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2,
  signDisplay: "always",
})

function series(seed: number, rising: boolean) {
  let state = seed
  let value = 100
  return Array.from({ length: 30 }, (_, index) => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return { index, value }
  })
}

function Sparkline({ seed, rising }: { seed: number; rising: boolean }) {
  const key = rising ? "up" : "down"
  const id = React.useId()

  return (
    <ChartContainer
      config={chartConfig}
      aria-hidden
      className="aspect-auto h-8 w-18 shrink-0"
    >
      <AreaChart
        accessibilityLayer={false}
        data={series(seed, rising)}
        margin={{ top: 2, right: 0, left: 0, bottom: 2 }}
      >
        <defs>
          <linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
            <stop
              offset="0%"
              stopColor={`var(--color-${key})`}
              stopOpacity={0.25}
            />
            <stop
              offset="100%"
              stopColor={`var(--color-${key})`}
              stopOpacity={0.02}
            />
          </linearGradient>
        </defs>
        <YAxis hide domain={["dataMin", "dataMax"]} />
        <Area
          dataKey="value"
          type="linear"
          stroke={`var(--color-${key})`}
          strokeWidth={1.5}
          fill={`url(#${id})`}
          isAnimationActive={false}
          dot={false}
        />
      </AreaChart>
    </ChartContainer>
  )
}

export function AreaChartSparkline() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Watchlist</CardTitle>
        <CardDescription>Small area charts next to each price</CardDescription>
      </CardHeader>
      <CardContent>
        <ul className="flex flex-col">
          {stocks.map((stock) => {
            const rising = stock.change >= 0

            return (
              <li
                key={stock.symbol}
                className="flex items-center gap-3 border-border py-2.25 not-first:border-t"
              >
                <span className="flex min-w-0 flex-1 flex-col">
                  <span className="text-base font-semibold">
                    {stock.symbol}
                  </span>
                  <span className="truncate text-xs text-muted-foreground">
                    {stock.name}
                  </span>
                </span>
                <Sparkline seed={stock.seed} rising={rising} />
                <span className="flex flex-col items-end gap-0.75">
                  <span className="text-sm font-semibold tabular-nums">
                    {priceFormat.format(stock.price)}
                  </span>
                  <span
                    data-trend={rising ? "up" : "down"}
                    className="min-w-13 rounded-md px-1.5 py-0.5 text-end text-xs font-semibold text-primary-foreground tabular-nums data-[trend=down]:bg-destructive data-[trend=up]:bg-green-500 dark:text-background"
                  >
                    {changeFormat.format(stock.change)}%
                  </span>
                </span>
              </li>
            )
          })}
        </ul>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartSparkline } from "@/components/charts/area-chart-sparkline"
```

```tsx
<AreaChartSparkline />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-sparkline.tsx"
import { cn } from "cn"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  type ChartConfig,
  ChartContainer,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const stocks = [
  { symbol: "ACME", name: "Acme Corp.", price: 254.32, change: 1.28, seed: 41 },
  { symbol: "GLBX", name: "Globex", price: 512.08, change: -0.64, seed: 52 },
  { symbol: "INIT", name: "Initech", price: 186.4, change: 2.91, seed: 63 },
  { symbol: "UMBR", name: "Umbrella", price: 438.15, change: -1.87, seed: 74 },
]

const chartConfig = {
  up: { label: "Rising", color: "green-500" },
  down: { label: "Falling", color: "destructive" },
} satisfies ChartConfig

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function series(seed: number, rising: boolean) {
  let state = seed
  let value = 100
  return Array.from({ length: 30 }, (_, index) => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return { index, value }
  })
}

function Sparkline({ seed, rising }: { seed: number; rising: boolean }) {
  const color = chartConfig[rising ? "up" : "down"].color

  return (
    <ChartContainer
      config={chartConfig}
      accessibilityElementsHidden
      importantForAccessibility="no-hide-descendants"
      className="h-8 w-18 shrink-0"
    >
      <AreaChart
        data={series(seed, rising)}
        margin={{ top: 2, right: 0, left: 0, bottom: 2 }}
      >
        <YAxis hide domain={["dataMin", "dataMax"]} />
        <Area
          isAnimationActive={false}
          dataKey="value"
          type="linear"
          stroke={color}
          strokeWidth={1.5}
          fill={{
            stops: [
              { offset: 0, color, opacity: 0.25 },
              { offset: 1, color, opacity: 0.02 },
            ],
          }}
        />
      </AreaChart>
    </ChartContainer>
  )
}

export function AreaChartSparkline() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Watchlist</CardTitle>
        <CardDescription>Small area charts next to each price</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          {stocks.map((stock, index) => {
            const rising = stock.change >= 0

            return (
              <View
                key={stock.symbol}
                className={cn(
                  "flex-row items-center gap-3 border-border py-2.25",
                  index > 0 && "border-t"
                )}
              >
                <View className="min-w-0 flex-1">
                  <Text className="text-base font-semibold">
                    {stock.symbol}
                  </Text>
                  <Text
                    numberOfLines={1}
                    className="text-xs text-muted-foreground"
                  >
                    {stock.name}
                  </Text>
                </View>
                <Sparkline seed={stock.seed} rising={rising} />
                <View className="items-end gap-0.75">
                  <Text className="text-sm font-semibold tabular-nums">
                    {formatPrice(stock.price)}
                  </Text>
                  <View
                    className={cn(
                      "min-w-13 rounded-md px-1.5 py-0.5",
                      rising ? "bg-green-500" : "bg-destructive"
                    )}
                  >
                    <Text className="text-right text-xs font-semibold text-primary-foreground tabular-nums dark:text-background">
                      {formatPrice(stock.change, true)}%
                    </Text>
                  </View>
                </View>
              </View>
            )
          })}
        </View>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartSparkline.swift"
import Charts
import SwiftUI

private let stocks: [(symbol: String, name: String, price: Double, change: Double, seed: Int)] = [
  ("ACME", "Acme Corp.", 254.32, 1.28, 41),
  ("GLBX", "Globex", 512.08, -0.64, 52),
  ("INIT", "Initech", 186.4, 2.91, 63),
  ("UMBR", "Umbrella", 438.15, -1.87, 74),
]

private let chartConfig: ChartConfig = [
  "up": .init("Rising", color: Palette.green500),
  "down": .init("Falling", color: EsuissColor.destructive),
]

private func series(_ seed: Int, rising: Bool) -> [Double] {
  var state = seed
  var value = 100.0
  return (0..<30).map { _ in
    state = (state * 16807) % 2147483647
    value *= 1 + (Double(state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return value
  }
}

private struct Sparkline: View {
  let seed: Int
  let rising: Bool

  var body: some View {
    let values = series(seed, rising: rising)
    let color = chartConfig.color(rising ? "up" : "down")
    ChartContainer(config: chartConfig) {
      Chart {
        ForEach(values.indices, id: \.self) { index in
          AreaMark(x: .value("Day", index), yStart: .value("Base", values.min() ?? 0), yEnd: .value("Value", values[index]))
            .interpolationMethod(.linear)
            .foregroundStyle(LinearGradient(colors: [color.opacity(0.25), color.opacity(0.02)], startPoint: .top, endPoint: .bottom))
          LineMark(x: .value("Day", index), y: .value("Value", values[index]))
            .interpolationMethod(.linear)
            .lineStyle(StrokeStyle(lineWidth: 1.5, lineCap: .round, lineJoin: .round))
            .foregroundStyle(color)
        }
      }
      .chartXScale(domain: 0...(values.count - 1))
      .chartYScale(domain: (values.min() ?? 0)...(values.max() ?? 1))
      .chartXAxis(.hidden)
      .chartYAxis(.hidden)
      .padding(.vertical, 2)
    }
    .frame(width: 72, height: 32)
    .accessibilityHidden(true)
  }
}

public struct AreaChartSparkline: View {
  @Environment(\.locale) private var locale
  @Environment(\.colorScheme) private var colorScheme

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Watchlist", description: "Small area charts next to each price")
      CardContent {
        VStack(spacing: 0) {
          ForEach(stocks.indices, id: \.self) { index in
            if index > 0 {
              EsuissColor.border.frame(height: 1)
            }
            row(stocks[index])
          }
        }
      }
    }
  }

  private func row(_ stock: (symbol: String, name: String, price: Double, change: Double, seed: Int)) -> some View {
    let rising = stock.change >= 0
    return HStack(spacing: 12) {
      VStack(alignment: .leading, spacing: 0) {
        Text(verbatim: stock.symbol)
          .textStyle(.base, weight: .semibold)
        Text(verbatim: stock.name)
          .textStyle(.xs)
          .foregroundStyle(EsuissColor.mutedForeground)
          .lineLimit(1)
      }
      .frame(maxWidth: .infinity, alignment: .leading)
      Sparkline(seed: stock.seed, rising: rising)
      VStack(alignment: .trailing, spacing: 3) {
        Text(stock.price, format: .number.precision(.fractionLength(2)).locale(locale))
          .textStyle(.sm, weight: .semibold)
          .monospacedDigit()
        Text("\(stock.change, format: .number.precision(.fractionLength(2)).sign(strategy: .always()).locale(locale))%")
          .textStyle(.xs, weight: .semibold)
          .monospacedDigit()
          .foregroundStyle(colorScheme == .dark ? EsuissColor.background : EsuissColor.primaryForeground)
          .padding(.horizontal, 6)
          .padding(.vertical, 2)
          .frame(minWidth: 52, alignment: .trailing)
          .background(rising ? Palette.green500 : EsuissColor.destructive, in: RoundedRectangle(cornerRadius: Radius.md, style: .continuous))
      }
    }
    .padding(.vertical, 9)
    .accessibilityElement(children: .combine)
  }
}
```

```kt title="kotlin/charts/AreaChartSparkline.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.Separator
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography
import java.text.NumberFormat
import java.util.Locale

private class Stock(val symbol: String, val name: String, val price: Double, val change: Double, val seed: Long)

private class SparkPoint(val index: Int, val value: Double)

private val stocks = listOf(
    Stock("ACME", "Acme Corp.", 254.32, 1.28, 41),
    Stock("GLBX", "Globex", 512.08, -0.64, 52),
    Stock("INIT", "Initech", 186.4, 2.91, 63),
    Stock("UMBR", "Umbrella", 438.15, -1.87, 74),
)

private val chartConfig = ChartConfig(
    "up" to ChartConfigItem("Rising") { Palette.green500 },
    "down" to ChartConfigItem("Falling") { destructive },
)

private fun series(seed: Long, rising: Boolean): List<SparkPoint> {
    var state = seed
    var value = 100.0
    return List(30) { index ->
        state = state * 16807 % 2147483647
        value *= 1 + ((state - 1) / 2147483646.0 - if (rising) 0.44 else 0.56) * 0.02
        SparkPoint(index, value)
    }
}

private fun twoDigits(): NumberFormat = NumberFormat.getNumberInstance(Locale.US).apply {
    minimumFractionDigits = 2
    maximumFractionDigits = 2
}

@Composable
private fun Sparkline(seed: Long, rising: Boolean) {
    val key = if (rising) "up" else "down"
    val data = remember(seed, rising) { series(seed, rising) }
    ChartContainer(
        chartConfig,
        Modifier
            .size(72.dp, 32.dp)
            .clearAndSetSemantics { },
    ) {
        AreaChart(data, margin = ChartMargin(top = 2.dp, right = 0.dp, bottom = 2.dp, left = 0.dp)) {
            YAxis(hide = true, domain = data.minOf { it.value }..data.maxOf { it.value })
            Area(
                key,
                value = { it.value },
                strokeWidth = 1.5.dp,
                fill = ChartFill.VerticalGradient(topAlpha = 0.25f, bottomAlpha = 0.02f),
                activeDot = null,
                isAnimationActive = false,
            )
        }
    }
}

@Composable
fun AreaChartSparkline(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    val priceFormat = remember { twoDigits() }
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Watchlist", description = "Small area charts next to each price")
        CardContent {
            stocks.forEachIndexed { index, stock ->
                val rising = stock.change >= 0
                if (index > 0) Separator()
                Row(
                    Modifier
                        .fillMaxWidth()
                        .padding(vertical = 9.dp),
                    horizontalArrangement = Arrangement.spacedBy(12.dp),
                    verticalAlignment = Alignment.CenterVertically,
                ) {
                    Column(Modifier.weight(1f)) {
                        BasicText(stock.symbol, style = Typography.base.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold))
                        BasicText(
                            stock.name,
                            style = Typography.xs.copy(color = colors.mutedForeground),
                            maxLines = 1,
                            overflow = TextOverflow.Ellipsis,
                        )
                    }
                    Sparkline(stock.seed, rising)
                    Column(horizontalAlignment = Alignment.End, verticalArrangement = Arrangement.spacedBy(3.dp)) {
                        BasicText(
                            priceFormat.format(stock.price),
                            style = Typography.sm.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                        )
                        BasicText(
                            "${if (stock.change >= 0) "+" else "-"}${priceFormat.format(kotlin.math.abs(stock.change))}%",
                            Modifier
                                .widthIn(min = 52.dp)
                                .background(if (rising) Palette.green500 else colors.destructive, RoundedCornerShape(Radius.md))
                                .padding(horizontal = 6.dp, vertical = 2.dp),
                            style = Typography.xs.copy(
                                color = if (colors.isDark) colors.background else colors.primaryForeground,
                                fontWeight = FontWeight.SemiBold,
                                fontFeatureSettings = "tnum",
                                textAlign = TextAlign.End,
                            ),
                        )
                    }
                }
            }
        }
    }
}
```

**React Native**

Each row shows a symbol and company name, a tiny area chart without axes, the price and a colored badge with the percentage change. The sparkline turns green when the change is positive and red when it is negative, using the `up` and `down` colors in `chartConfig`. The charts are hidden from screen readers because the row text already carries the values. Each sparkline sets `isAnimationActive={false}` and draws without the enter animation.

Replace the `stocks` array with your own symbols, prices and changes, and swap the generated `series` data for real price history. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-sparkline
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-sparkline
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-sparkline
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-sparkline --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-sparkline
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-sparkline --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

3. Copy and paste the following code into `components/charts/area-chart-sparkline.tsx`:

- `uniwind/components/charts/area-chart-sparkline.tsx`: shown above

4. Update the import paths to match your project setup.

**NativeWind**

1. Install the following dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

3. Copy and paste the following code into `components/charts/area-chart-sparkline.tsx`:

```tsx title="nativewind/components/charts/area-chart-sparkline.tsx"
import { cn } from "cn"
import { View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  type ChartConfig,
  ChartContainer,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const stocks = [
  { symbol: "ACME", name: "Acme Corp.", price: 254.32, change: 1.28, seed: 41 },
  { symbol: "GLBX", name: "Globex", price: 512.08, change: -0.64, seed: 52 },
  { symbol: "INIT", name: "Initech", price: 186.4, change: 2.91, seed: 63 },
  { symbol: "UMBR", name: "Umbrella", price: 438.15, change: -1.87, seed: 74 },
]

const chartConfig = {
  up: { label: "Rising", color: "green-500" },
  down: { label: "Falling", color: "destructive" },
} satisfies ChartConfig

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function series(seed: number, rising: boolean) {
  let state = seed
  let value = 100
  return Array.from({ length: 30 }, (_, index) => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return { index, value }
  })
}

function Sparkline({ seed, rising }: { seed: number; rising: boolean }) {
  const color = chartConfig[rising ? "up" : "down"].color

  return (
    <ChartContainer
      config={chartConfig}
      accessibilityElementsHidden
      importantForAccessibility="no-hide-descendants"
      className="h-8 w-[4.5rem] shrink-0"
    >
      <AreaChart
        data={series(seed, rising)}
        margin={{ top: 2, right: 0, left: 0, bottom: 2 }}
      >
        <YAxis hide domain={["dataMin", "dataMax"]} />
        <Area
          isAnimationActive={false}
          dataKey="value"
          type="linear"
          stroke={color}
          strokeWidth={1.5}
          fill={{
            stops: [
              { offset: 0, color, opacity: 0.25 },
              { offset: 1, color, opacity: 0.02 },
            ],
          }}
        />
      </AreaChart>
    </ChartContainer>
  )
}

export function AreaChartSparkline() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Watchlist</CardTitle>
        <CardDescription>Small area charts next to each price</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          {stocks.map((stock, index) => {
            const rising = stock.change >= 0

            return (
              <View
                key={stock.symbol}
                className={cn(
                  "flex-row items-center gap-3 border-border py-[0.5625rem]",
                  index > 0 && "border-t"
                )}
              >
                <View className="min-w-0 flex-1">
                  <Text className="text-base font-semibold">
                    {stock.symbol}
                  </Text>
                  <Text
                    numberOfLines={1}
                    className="text-xs text-muted-foreground"
                  >
                    {stock.name}
                  </Text>
                </View>
                <Sparkline seed={stock.seed} rising={rising} />
                <View className="items-end gap-[0.1875rem]">
                  <Text className="text-sm font-semibold tabular-nums">
                    {formatPrice(stock.price)}
                  </Text>
                  <View
                    className={cn(
                      "min-w-[3.25rem] rounded-md px-1.5 py-0.5",
                      rising ? "bg-green-500" : "bg-destructive"
                    )}
                  >
                    <Text className="text-right text-xs font-semibold text-primary-foreground tabular-nums dark:text-background">
                      {formatPrice(stock.change, true)}%
                    </Text>
                  </View>
                </View>
              </View>
            )
          })}
        </View>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart), [Text](https://suiss.app/ui/docs/components/text).

2. Copy and paste the following code into `components/charts/area-chart-sparkline.tsx`:

```tsx title="stylesheet/components/charts/area-chart-sparkline.tsx"
import { StyleSheet, View } from "react-native"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  type ChartConfig,
  ChartContainer,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, palette, useTheme } from "@/components/ui/theme"

const stocks = [
  { symbol: "ACME", name: "Acme Corp.", price: 254.32, change: 1.28, seed: 41 },
  { symbol: "GLBX", name: "Globex", price: 512.08, change: -0.64, seed: 52 },
  { symbol: "INIT", name: "Initech", price: 186.4, change: 2.91, seed: 63 },
  { symbol: "UMBR", name: "Umbrella", price: 438.15, change: -1.87, seed: 74 },
]

const chartConfig = {
  up: { label: "Rising", color: "green-500" },
  down: { label: "Falling", color: "destructive" },
} satisfies ChartConfig

const styles = StyleSheet.create({
  sparkline: { height: 32, width: 72, flexShrink: 0 },
  row: {
    flexDirection: "row",
    alignItems: "center",
    gap: 12,
    paddingVertical: 9,
  },
  name: { minWidth: 0, flex: 1 },
  symbol: { ...fontSize.base, fontWeight: "600" },
  company: { ...fontSize.xs },
  prices: { alignItems: "flex-end", gap: 3 },
  price: { ...fontSize.sm, fontWeight: "600", fontVariant: ["tabular-nums"] },
  badge: {
    minWidth: 52,
    borderRadius: 6,
    paddingHorizontal: 6,
    paddingVertical: 2,
  },
  change: {
    ...fontSize.xs,
    textAlign: "right",
    fontWeight: "600",
    fontVariant: ["tabular-nums"],
  },
})

function formatPrice(value: number, signed = false) {
  const sign = signed && value >= 0 ? "+" : ""
  try {
    return `${sign}${new Intl.NumberFormat("en-US", {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(value)}`
  } catch {
    const [whole = "0", fraction = "00"] = value.toFixed(2).split(".")
    return `${sign}${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${fraction}`
  }
}

function series(seed: number, rising: boolean) {
  let state = seed
  let value = 100
  return Array.from({ length: 30 }, (_, index) => {
    state = (state * 16807) % 2147483647
    value *= 1 + ((state - 1) / 2147483646 - (rising ? 0.44 : 0.56)) * 0.02
    return { index, value }
  })
}

function Sparkline({ seed, rising }: { seed: number; rising: boolean }) {
  const color = chartConfig[rising ? "up" : "down"].color

  return (
    <ChartContainer
      config={chartConfig}
      accessibilityElementsHidden
      importantForAccessibility="no-hide-descendants"
      style={styles.sparkline}
    >
      <AreaChart
        data={series(seed, rising)}
        margin={{ top: 2, right: 0, left: 0, bottom: 2 }}
      >
        <YAxis hide domain={["dataMin", "dataMax"]} />
        <Area
          isAnimationActive={false}
          dataKey="value"
          type="linear"
          stroke={color}
          strokeWidth={1.5}
          fill={{
            stops: [
              { offset: 0, color, opacity: 0.25 },
              { offset: 1, color, opacity: 0.02 },
            ],
          }}
        />
      </AreaChart>
    </ChartContainer>
  )
}

export function AreaChartSparkline() {
  const { colors, isDark } = useTheme()
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Watchlist</CardTitle>
        <CardDescription>Small area charts next to each price</CardDescription>
      </CardHeader>
      <CardContent>
        <View>
          {stocks.map((stock, index) => {
            const rising = stock.change >= 0

            return (
              <View
                key={stock.symbol}
                style={[
                  styles.row,
                  index > 0 && {
                    borderTopWidth: 1,
                    borderColor: colors.border,
                  },
                ]}
              >
                <View style={styles.name}>
                  <Text style={styles.symbol}>{stock.symbol}</Text>
                  <Text
                    numberOfLines={1}
                    style={[styles.company, { color: colors.mutedForeground }]}
                  >
                    {stock.name}
                  </Text>
                </View>
                <Sparkline seed={stock.seed} rising={rising} />
                <View style={styles.prices}>
                  <Text style={styles.price}>{formatPrice(stock.price)}</Text>
                  <View
                    style={[
                      styles.badge,
                      {
                        backgroundColor: rising
                          ? palette.green500
                          : colors.destructive,
                      },
                    ]}
                  >
                    <Text
                      style={[
                        styles.change,
                        {
                          color: isDark
                            ? colors.background
                            : colors.primaryForeground,
                        },
                      ]}
                    >
                      {formatPrice(stock.change, true)}%
                    </Text>
                  </View>
                </View>
              </View>
            )
          })}
        </View>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartSparkline.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartSparkline.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

- `kotlin/components/Separator.kt`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartSparkline } from "@/components/charts/area-chart-sparkline"
```

```tsx
<AreaChartSparkline />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaSparklineExample: View {
  var body: some View {
    AreaChartSparkline()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartSparkline

@Composable
fun AreaSparklineExample() {
    AreaChartSparkline()
}
```



## Area Chart Stacked Expand

Two stacked areas normalized so every month fills 100%, showing each series' share rather than its value.

Source: https://suiss.app/ui/docs/charts/area-chart#stacked-expand

**React**

**Example**

```tsx title="components/charts/area-chart-stacked-expand.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartStackedExpand() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked to 100%</CardTitle>
        <CardDescription>Each month adds up to 100%</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            stackOffset="expand"
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              ticks={[0, 0.5, 1]}
              tickFormatter={(value: number) => `${Math.round(value * 100)}%`}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              stroke="var(--color-mobile)"
              fill="var(--color-mobile)"
              fillOpacity={0.35}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              stroke="var(--color-desktop)"
              fill="var(--color-desktop)"
              fillOpacity={0.35}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two stacked areas stretched so every month fills the full height, turning absolute numbers into shares. Pick it over the regular stacked chart when the split between series matters more than the total.

Replace `chartData` and rename the series keys in the data, the areas and `chartConfig`. Every series needs the same `stackId` to be normalized together. The tooltip shows the original values, not percentages; add a tooltip formatter if readers need the share. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked-expand
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked-expand
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-stacked-expand.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartStackedExpand() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked to 100%</CardTitle>
        <CardDescription>Each month adds up to 100%</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            stackOffset="expand"
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              ticks={[0, 0.5, 1]}
              tickFormatter={(value: number) => `${Math.round(value * 100)}%`}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              stroke="var(--color-mobile)"
              fill="var(--color-mobile)"
              fillOpacity={0.35}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              stroke="var(--color-desktop)"
              fill="var(--color-desktop)"
              fillOpacity={0.35}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartStackedExpand } from "@/components/charts/area-chart-stacked-expand"
```

```tsx
<AreaChartStackedExpand />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-stacked-expand.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStackedExpand() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked to 100%</CardTitle>
        <CardDescription>Each month adds up to 100%</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked to 100%"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            stackOffset="expand"
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={[0, 0.5, 1]}
              tickFormatter={(value: number) => `${Math.round(value * 100)}%`}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartStackedExpand.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
  "mobile": .init("Mobile", color: EsuissColor.chart2),
]

private let order = ["mobile", "desktop"]

private func value(_ key: String, _ index: Int) -> Double {
  key == "desktop" ? chartData[index].desktop : chartData[index].mobile
}

private func band(_ key: String, _ index: Int) -> (start: Double, end: Double) {
  let total = chartData[index].desktop + chartData[index].mobile
  let position = order.firstIndex(of: key) ?? 0
  let start = order.prefix(position).reduce(0) { $0 + value($1, index) }
  return (start / total, (start + value(key, index)) / total)
}

public struct AreaChartStackedExpand: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Stacked to 100%", description: "Each month adds up to 100%")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(order, id: \.self) { key in
                ForEach(chartData.indices, id: \.self) { index in
                  AreaMark(
                    x: .value("Month", index),
                    yStart: .value("Start", band(key, index).start),
                    yEnd: .value("End", band(key, index).end),
                    series: .value("Series", key)
                  )
                  .interpolationMethod(.catmullRom)
                  .foregroundStyle(chartConfig.color(key).opacity(0.35))
                  LineMark(x: .value("Month", index), y: .value("End", band(key, index).end), series: .value("Series", key))
                    .interpolationMethod(.catmullRom)
                    .lineStyle(StrokeStyle(lineWidth: 1, lineCap: .round, lineJoin: .round))
                    .foregroundStyle(chartConfig.color(key))
                }
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYScale(domain: 0...1)
            .chartYAxis { ChartAxis.y(values: [0.0, 0.5, 1]) { "\(Int(($0 * 100).rounded()))%" } }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Stacked to 100%",
              items: { index in order.map { ChartTooltipItem($0, value: value($0, index)) } }
            ) { payload in
              ChartTooltipContent(payload, indicator: .line)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartStackedExpand.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartAxisOrientation
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartStackOffset
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator
import kotlin.math.roundToInt

private class AreaExpandRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaExpandRow("January", 186.0, 80.0),
    AreaExpandRow("February", 305.0, 200.0),
    AreaExpandRow("March", 237.0, 120.0),
    AreaExpandRow("April", 173.0, 190.0),
    AreaExpandRow("May", 209.0, 130.0),
    AreaExpandRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
    "mobile" to ChartConfigItem("Mobile") { chart2 },
)

@Composable
fun AreaChartStackedExpand(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Stacked to 100%", description = "Each month adds up to 100%")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 12.dp),
                    stackOffset = ChartStackOffset.Expand,
                    accessibilityLabel = "Stacked to 100%",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    YAxis(
                        orientation = ChartAxisOrientation.Right,
                        tickMargin = 6.dp,
                        ticks = listOf(0.0, 0.5, 1.0),
                        tickFormatter = { "${(it * 100).roundToInt()}%" },
                    )
                    ChartTooltip { ChartTooltipContent(indicator = ChartTooltipIndicator.Line) }
                    Area("mobile", value = { it.mobile }, curve = ChartCurve.Natural, fill = ChartFill.Solid(alpha = 0.35f), stackId = "a")
                    Area("desktop", value = { it.desktop }, curve = ChartCurve.Natural, fill = ChartFill.Solid(alpha = 0.35f), stackId = "a")
                }
            }
        }
    }
}
```

**React Native**

Desktop and mobile areas share one stack with `stackOffset="expand"`, so the chart shows the proportion of each series rather than raw totals. A value axis on the right reads 0%, 50% and 100%, and the tooltip lists both series.

Replace `chartData` with your records and change each `dataKey` to match your fields. Rename the series or change their colors in `chartConfig`. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked-expand
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked-expand
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked-expand
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked-expand --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked-expand
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked-expand --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked-expand.tsx`:

- `uniwind/components/charts/area-chart-stacked-expand.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked-expand.tsx`:

```tsx title="nativewind/components/charts/area-chart-stacked-expand.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStackedExpand() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked to 100%</CardTitle>
        <CardDescription>Each month adds up to 100%</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked to 100%"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            stackOffset="expand"
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={[0, 0.5, 1]}
              tickFormatter={(value: number) => `${Math.round(value * 100)}%`}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked-expand.tsx`:

```tsx title="stylesheet/components/charts/area-chart-stacked-expand.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStackedExpand() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked to 100%</CardTitle>
        <CardDescription>Each month adds up to 100%</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked to 100%"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            stackOffset="expand"
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={[0, 0.5, 1]}
              tickFormatter={(value: number) => `${Math.round(value * 100)}%`}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              fillOpacity={0.35}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartStackedExpand.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartStackedExpand.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartStackedExpand } from "@/components/charts/area-chart-stacked-expand"
```

```tsx
<AreaChartStackedExpand />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaStackedExpandExample: View {
  var body: some View {
    AreaChartStackedExpand()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartStackedExpand

@Composable
fun AreaStackedExpandExample() {
    AreaChartStackedExpand()
}
```



## Area Chart Stacked

Two areas stacked on top of each other so the top edge shows the combined total, with a legend.

Source: https://suiss.app/ui/docs/charts/area-chart#stacked

**React**

**Example**

```tsx title="components/charts/area-chart-stacked.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>Desktop and mobile combined</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="dot" />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              stroke="var(--color-mobile)"
              strokeWidth={2}
              fill="var(--color-mobile)"
              fillOpacity={0.2}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.2}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two series stacked so the top edge shows the combined total, with a legend underneath. Use it when both the total and each part's contribution matter, as in desktop plus mobile traffic.

Replace `chartData` and rename the series keys in the data, both areas and `chartConfig`; the legend reads labels and colors from the config. Give every series the same `stackId`; the first one declared sits at the bottom. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-stacked.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig

export function AreaChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>Desktop and mobile combined</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="dot" />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              stroke="var(--color-mobile)"
              strokeWidth={2}
              fill="var(--color-mobile)"
              fillOpacity={0.2}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.2}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartStacked } from "@/components/charts/area-chart-stacked"
```

```tsx
<AreaChartStacked />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>Desktop and mobile combined</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="dot" />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartStacked.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
  "mobile": .init("Mobile", color: EsuissColor.chart2),
]

private let order = ["mobile", "desktop"]

private func value(_ key: String, _ index: Int) -> Double {
  key == "desktop" ? chartData[index].desktop : chartData[index].mobile
}

private func band(_ key: String, _ index: Int) -> (start: Double, end: Double) {
  let position = order.firstIndex(of: key) ?? 0
  let start = order.prefix(position).reduce(0) { $0 + value($1, index) }
  return (start, start + value(key, index))
}

public struct AreaChartStacked: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Stacked", description: "Desktop and mobile combined")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(order, id: \.self) { key in
                ForEach(chartData.indices, id: \.self) { index in
                  AreaMark(
                    x: .value("Month", index),
                    yStart: .value("Start", band(key, index).start),
                    yEnd: .value("End", band(key, index).end),
                    series: .value("Series", key)
                  )
                  .interpolationMethod(.catmullRom)
                  .foregroundStyle(chartConfig.color(key).opacity(0.2))
                  LineMark(x: .value("Month", index), y: .value("End", band(key, index).end), series: .value("Series", key))
                    .interpolationMethod(.catmullRom)
                    .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                    .foregroundStyle(chartConfig.color(key))
                }
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Stacked",
              items: { index in order.map { ChartTooltipItem($0, value: value($0, index)) } }
            ) { payload in
              ChartTooltipContent(payload, indicator: .dot)
            }
          }
          ChartLegendContent()
        }
        .frame(height: 224)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartStacked.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator

private class AreaStackedRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaStackedRow("January", 186.0, 80.0),
    AreaStackedRow("February", 305.0, 200.0),
    AreaStackedRow("March", 237.0, 120.0),
    AreaStackedRow("April", 173.0, 190.0),
    AreaStackedRow("May", 209.0, 130.0),
    AreaStackedRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
    "mobile" to ChartConfigItem("Mobile") { chart2 },
)

@Composable
fun AreaChartStacked(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Stacked", description = "Desktop and mobile combined")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 12.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Stacked",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip { ChartTooltipContent(indicator = ChartTooltipIndicator.Dot) }
                    ChartLegend()
                    Area(
                        "mobile",
                        value = { it.mobile },
                        curve = ChartCurve.Natural,
                        strokeWidth = 2.dp,
                        fill = ChartFill.Solid(alpha = 0.2f),
                        stackId = "a",
                    )
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Natural,
                        strokeWidth = 2.dp,
                        fill = ChartFill.Solid(alpha = 0.2f),
                        stackId = "a",
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

Desktop and mobile areas are stacked on top of each other with the same `stackId`, so the top edge shows the combined total. A legend below the plot names both series, and the tooltip lists each value with a dot indicator.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Add, rename or recolor series in `chartConfig`; the legend picks the changes up. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-stacked
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-stacked --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked.tsx`:

- `uniwind/components/charts/area-chart-stacked.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked.tsx`:

```tsx title="nativewind/components/charts/area-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>Desktop and mobile combined</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="dot" />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-stacked.tsx`:

```tsx title="stylesheet/components/charts/area-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
  mobile: { label: "Mobile", color: "chart-2" },
} satisfies ChartConfig

export function AreaChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>Desktop and mobile combined</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="dot" />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Area
              dataKey="mobile"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
            <Area
              dataKey="desktop"
              type="natural"
              stackId="a"
              strokeWidth={2}
              fillOpacity={0.2}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartStacked.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartStacked.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartStacked } from "@/components/charts/area-chart-stacked"
```

```tsx
<AreaChartStacked />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaStackedExample: View {
  var body: some View {
    AreaChartStacked()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartStacked

@Composable
fun AreaStackedExample() {
    AreaChartStacked()
}
```



## Area Chart Step

A single filled area drawn as steps, holding each value flat until the next reading.

Source: https://suiss.app/ui/docs/charts/area-chart#step

**React**

**Example**

```tsx title="components/charts/area-chart-step.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartStep() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Step</CardTitle>
        <CardDescription>
          Each value holds until the next reading
        </CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="step"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A single filled area drawn as steps that hold each value flat until the next reading. It suits values that change in discrete jumps, like prices, plan tiers or inventory counts.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`. Set the curve type to `stepAfter` or `stepBefore` to move the jump to the other side of each point. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-step
```

Works in any project with a `components.json`. See [Installation](https://suiss.app/ui/docs/installation#add-components) for the one-line registry setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-step
```

**Manual**

1. Install the following dependencies:

```bash title="Terminal"
npm install recharts
```

2. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

3. Copy and paste the following code into your project.

```tsx title="components/charts/area-chart-step.tsx"
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

export function AreaChartStep() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Step</CardTitle>
        <CardDescription>
          Each value holds until the next reading
        </CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <AreaChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="step"
              stroke="var(--color-desktop)"
              strokeWidth={2}
              fill="var(--color-desktop)"
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

4. Update the import paths to match your project setup.

### Usage

```tsx
import { AreaChartStep } from "@/components/charts/area-chart-step"
```

```tsx
<AreaChartStep />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/area-chart-step.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartStep() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Step</CardTitle>
        <CardDescription>
          Each value holds until the next reading
        </CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Step"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="step"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/AreaChartStep.swift"
import Charts
import SwiftUI

private let chartData: [(month: String, desktop: Double, mobile: Double)] = [
  ("January", 186, 80),
  ("February", 305, 200),
  ("March", 237, 120),
  ("April", 173, 190),
  ("May", 209, 130),
  ("June", 264, 140),
]

private let chartConfig: ChartConfig = [
  "desktop": .init("Desktop", color: EsuissColor.chart1),
]

public struct AreaChartStep: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Step", description: "Each value holds until the next reading")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                AreaMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.stepCenter)
                  .foregroundStyle(chartConfig.color("desktop").opacity(0.18))
                LineMark(x: .value("Month", index), y: .value("Desktop", chartData[index].desktop))
                  .interpolationMethod(.stepCenter)
                  .lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
                  .foregroundStyle(chartConfig.color("desktop"))
              }
              .chartReveal(progress, x: 0...(chartData.count - 1))
              if let selection {
                PointMark(x: .value("Month", selection), y: .value("Desktop", chartData[selection].desktop))
                  .symbolSize(64)
                  .foregroundStyle(chartConfig.color("desktop"))
              }
            }
            .chartXScale(domain: 0...(chartData.count - 1), range: .plotDimension(padding: 12))
            .chartXAxis { ChartAxis.x(values: Array(chartData.indices)) { String(chartData[$0].month.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: Array(chartData.indices),
              labels: chartData.map(\.month),
              selection: $selection,
              accessibilityLabel: "Step",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload, indicator: .line)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/AreaChartStep.kt"
package com.esuiss.ui.charts

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.AreaChart
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardHeader
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.CardVariant
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartCurve
import com.esuiss.ui.components.ChartFill
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator

private class AreaStepRow(val month: String, val desktop: Double, val mobile: Double)

private val chartData = listOf(
    AreaStepRow("January", 186.0, 80.0),
    AreaStepRow("February", 305.0, 200.0),
    AreaStepRow("March", 237.0, 120.0),
    AreaStepRow("April", 173.0, 190.0),
    AreaStepRow("May", 209.0, 130.0),
    AreaStepRow("June", 264.0, 140.0),
)

private val chartConfig = ChartConfig(
    "desktop" to ChartConfigItem("Desktop") { chart1 },
)

@Composable
fun AreaChartStep(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Step", description = "Each value holds until the next reading")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                AreaChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 12.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Step",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip { ChartTooltipContent(indicator = ChartTooltipIndicator.Line) }
                    Area(
                        "desktop",
                        value = { it.desktop },
                        curve = ChartCurve.Step,
                        strokeWidth = 2.dp,
                        fill = ChartFill.Solid(alpha = 0.18f),
                    )
                }
            }
        }
    }
}
```

**React Native**

One series with `type="step"`, which draws flat runs between readings instead of a slope. Use it for values that change at discrete moments, such as prices or plan limits. It has a month axis, a dashed grid and a tooltip.

Replace `chartData` with your records and change each `dataKey` to match your fields. Set the label and color in `chartConfig`. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-step
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-step
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-step
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-step --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/area-chart-step
```

See [Installation](https://suiss.app/ui/docs/installation) for the `components.json` setup. Or use the [suiss/ui CLI](https://suiss.app/ui/docs/cli):

```bash title="Terminal"
npx @esuiss/ui@latest add charts area-chart-step --platform kotlin
```

**React Native**

The CLI also adds what it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

**React Native, SwiftUI, Jetpack Compose**

**Manual**

**React Native**

**Uniwind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-step.tsx`:

- `uniwind/components/charts/area-chart-step.tsx`: shown above

3. Update the import paths to match your project setup.

**NativeWind**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-step.tsx`:

```tsx title="nativewind/components/charts/area-chart-step.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartStep() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Step</CardTitle>
        <CardDescription>
          Each value holds until the next reading
        </CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Step"
          className="h-48 w-full"
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="step"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**StyleSheet**

1. Add the pieces it builds on: [Card](https://suiss.app/ui/docs/components/card), [Chart](https://suiss.app/ui/docs/components/chart).

2. Copy and paste the following code into `components/charts/area-chart-step.tsx`:

```tsx title="stylesheet/components/charts/area-chart-step.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Area,
  AreaChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", desktop: 186, mobile: 80 },
  { month: "February", desktop: 305, mobile: 200 },
  { month: "March", desktop: 237, mobile: 120 },
  { month: "April", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "June", desktop: 264, mobile: 140 },
]

const chartConfig = {
  desktop: { label: "Desktop", color: "chart-1" },
} satisfies ChartConfig

export function AreaChartStep() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Step</CardTitle>
        <CardDescription>
          Each value holds until the next reading
        </CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Step"
          style={{ height: 192 }}
        >
          <AreaChart
            data={chartData}
            margin={{ top: 10, right: 12, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Area
              dataKey="desktop"
              type="step"
              strokeWidth={2}
              fillOpacity={0.18}
            />
          </AreaChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

3. Update the import paths to match your project setup.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

3. Copy the source and every file it uses:

- `swift/Charts/AreaChartStep.swift`: shown above

- `swift/Components/Card.swift`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `swift/Components/Chart.swift`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `swift/Components/Haptics.swift`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://suiss.app/ui/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://suiss.app/ui/docs/components/separator.md)

4. Add the files to your app target.

**Jetpack Compose**

1. Apply the Compose compiler plugin, enable Compose, set `compileSdk` to 37 or higher and `minSdk` to 24 or higher, and add the dependencies:

```kotlin title="build.gradle.kts"
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
}
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

- `kotlin/charts/AreaChartStep.kt`: shown above

- `kotlin/components/Card.kt`: see [Card](https://suiss.app/ui/docs/components/card.md)

- `kotlin/components/Chart.kt`: see [Chart](https://suiss.app/ui/docs/components/chart.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://suiss.app/ui/docs/components/haptics.md)

- `kotlin/components/Icon.kt`: see [Icon](https://suiss.app/ui/docs/components/icon.md)

4. Update the `com.esuiss.ui` package names to match your project.

**React Native, SwiftUI, Jetpack Compose**

### Usage

**React Native**

```tsx
import { AreaChartStep } from "@/components/charts/area-chart-step"
```

```tsx
<AreaChartStep />
```

**SwiftUI**

```swift
import SwiftUI

struct AreaStepExample: View {
  var body: some View {
    AreaChartStep()
  }
}
```

**Jetpack Compose**

```kotlin
import androidx.compose.runtime.Composable
import com.esuiss.ui.charts.AreaChartStep

@Composable
fun AreaStepExample() {
    AreaChartStep()
}
```

