# Bar Chart

Ten bar charts for comparing values across categories, from a single series to stacked, grouped, horizontal, negative and range bars.

Bar 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/bar-chart

Bar charts compare a value across categories or periods. Start with the default for one series, group or stack bars when there are two, turn them horizontal for long category names, and use the negative or range variants when a value can drop below zero or spans a low and a high.

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.


## Bar Chart Default

A single series of rounded vertical bars, one per month.

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

**React**

**Example**

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

import { Bar, BarChart, 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 BarChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Bar chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar
              dataKey="desktop"
              fill="var(--color-desktop)"
              radius={6}
              maxBarSize={36}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

The plain bar chart: one series of rounded vertical bars with a month axis and a tooltip. Start from it whenever you compare a handful of discrete values.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`. Use `radius` for corner rounding and `maxBarSize` to cap bar width on wide containers. Focus the chart and use the arrow keys to move the tooltip between bars.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-default.tsx"
"use client"

import { Bar, BarChart, 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 BarChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Bar chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar
              dataKey="desktop"
              fill="var(--color-desktop)"
              radius={6}
              maxBarSize={36}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartDefault } from "@/components/charts/bar-chart-default"
```

```tsx
<BarChartDefault />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Bar chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Bar chart"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/BarChartDefault.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 BarChartDefault: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Bar chart", description: "Desktop visitors · January to June")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                BarMark(x: .value("Month", chartData[index].month), y: .value("Desktop", chartData[index].desktop * progress), width: .fixed(36))
                  .clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
                  .foregroundStyle(chartConfig.color("desktop"))
                ChartAnchorMark(x: .value("Month", chartData[index].month), y: .value("Desktop", chartData[index].desktop))
              }
            }
            .chartXAxis { ChartAxis.x(values: chartData.map(\.month)) { String($0.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: chartData.map(\.month),
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Bar chart",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartDefault.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.BarChart
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.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent

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

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

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

@Composable
fun BarChartDefault(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Bar chart", description = "Desktop visitors · January to June")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    accessibilityLabel = "Bar chart",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip(cursor = null) { ChartTooltipContent(hideLabel = true) }
                    Bar("desktop", value = { it.desktop }, radius = ChartRadius(6.dp), maxBarSize = 36.dp)
                }
            }
        }
    }
}
```

The baseline bar chart inside a `Card`: one rounded bar per month, a month axis, a dashed horizontal grid and a tooltip without a label. Start here and add series, stacking or labels as needed.

**React Native**

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

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-default
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-default --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-default.tsx`:

- `uniwind/components/charts/bar-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/bar-chart-default.tsx`:

```tsx title="nativewind/components/charts/bar-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Bar chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Bar chart"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36} />
          </BarChart>
        </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/bar-chart-default.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-default.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartDefault() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Bar chart</CardTitle>
        <CardDescription>Desktop visitors · January to June</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Bar chart"
          style={{ height: 192 }}
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36} />
          </BarChart>
        </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/BarChartDefault.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/BarChartDefault.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 { BarChartDefault } from "@/components/charts/bar-chart-default"
```

```tsx
<BarChartDefault />
```

**SwiftUI**

```swift
import SwiftUI

struct BarExample: View {
  var body: some View {
    BarChartDefault()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarExample() {
    BarChartDefault()
}
```



## Bar Chart Active

A week of step counts where clicking a bar selects it, dims the others and updates the header.

Source: https://suiss.app/ui/docs/charts/bar-chart#active

**React**

**Example**

```tsx title="components/charts/bar-chart-active.tsx"
"use client"

import * as React from "react"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  useActiveTooltipDataPoints,
  XAxis,
} from "recharts"

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

const chartData = [
  { day: "Monday", steps: 8412 },
  { day: "Tuesday", steps: 10230 },
  { day: "Wednesday", steps: 6120 },
  { day: "Thursday", steps: 12480 },
  { day: "Friday", steps: 9050 },
  { day: "Saturday", steps: 14320 },
  { day: "Sunday", steps: 4870 },
].map((item, index) => ({ ...item, index }))

const chartConfig = {
  steps: { label: "Steps", color: "var(--chart-4)" },
} satisfies ChartConfig

const stepsFormat = new Intl.NumberFormat("en-US")

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

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

  return null
}

export function BarChartActive() {
  const [selected, setSelected] = React.useState(5)
  const [highlighted, setHighlighted] = React.useState<number | null>(null)
  const day = chartData[selected]
  if (!day) return null
  const opacity = (index: number) => {
    if (index === selected) return 1
    if (index === highlighted) return 0.6
    return 0.3
  }

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-[color-mix(in_oklab,var(--color-orange-500),var(--foreground)_45%)] dark:text-orange-500">
          Steps
        </p>
        <p className="flex items-baseline gap-1" aria-live="polite">
          <span className="text-3xl font-semibold tracking-tight tabular-nums">
            {stepsFormat.format(day.steps)}
          </span>
          <span className="text-base font-semibold text-muted-foreground">
            steps
          </span>
        </p>
        <p className="text-sm text-muted-foreground">
          {day.day} · select a bar
        </p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full [&_.recharts-bar-rectangle]:cursor-pointer"
          onKeyDown={(event) => {
            if (
              (event.key === "Enter" || event.key === " ") &&
              highlighted !== null
            ) {
              event.preventDefault()
              setSelected(highlighted)
            }
          }}
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="day"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <Bar
              dataKey="steps"
              radius={5}
              maxBarSize={28}
              onClick={(_, index) => setSelected(index)}
            >
              {chartData.map((item) => (
                <Cell
                  key={item.day}
                  fill="var(--color-steps)"
                  fillOpacity={opacity(item.index)}
                  className="transition-[fill-opacity] duration-200"
                />
              ))}
            </Bar>
            <KeyboardPoint onChange={setHighlighted} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A week of step counts where one bar is selected at a time: the chosen day stays solid, the rest dim, and the header shows its value. Use it when a bar chart doubles as a picker for the detail shown above it.

Replace `chartData` and rename `steps` in the data, the `Bar` and `chartConfig`. The `selected` state sets the first selected bar, and the opacity of the dimmed bars sets the contrast. There is no tooltip: keyboard users move between bars with the arrow keys and select with Return or Space, and the header value is announced through a live region.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-active
```

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 bar-chart-active
```

**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/bar-chart-active.tsx"
"use client"

import * as React from "react"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  useActiveTooltipDataPoints,
  XAxis,
} from "recharts"

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

const chartData = [
  { day: "Monday", steps: 8412 },
  { day: "Tuesday", steps: 10230 },
  { day: "Wednesday", steps: 6120 },
  { day: "Thursday", steps: 12480 },
  { day: "Friday", steps: 9050 },
  { day: "Saturday", steps: 14320 },
  { day: "Sunday", steps: 4870 },
].map((item, index) => ({ ...item, index }))

const chartConfig = {
  steps: { label: "Steps", color: "var(--chart-4)" },
} satisfies ChartConfig

const stepsFormat = new Intl.NumberFormat("en-US")

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

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

  return null
}

export function BarChartActive() {
  const [selected, setSelected] = React.useState(5)
  const [highlighted, setHighlighted] = React.useState<number | null>(null)
  const day = chartData[selected]
  if (!day) return null
  const opacity = (index: number) => {
    if (index === selected) return 1
    if (index === highlighted) return 0.6
    return 0.3
  }

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-[color-mix(in_oklab,var(--color-orange-500),var(--foreground)_45%)] dark:text-orange-500">
          Steps
        </p>
        <p className="flex items-baseline gap-1" aria-live="polite">
          <span className="text-3xl font-semibold tracking-tight tabular-nums">
            {stepsFormat.format(day.steps)}
          </span>
          <span className="text-base font-semibold text-muted-foreground">
            steps
          </span>
        </p>
        <p className="text-sm text-muted-foreground">
          {day.day} · select a bar
        </p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full [&_.recharts-bar-rectangle]:cursor-pointer"
          onKeyDown={(event) => {
            if (
              (event.key === "Enter" || event.key === " ") &&
              highlighted !== null
            ) {
              event.preventDefault()
              setSelected(highlighted)
            }
          }}
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="day"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <Bar
              dataKey="steps"
              radius={5}
              maxBarSize={28}
              onClick={(_, index) => setSelected(index)}
            >
              {chartData.map((item) => (
                <Cell
                  key={item.day}
                  fill="var(--color-steps)"
                  fillOpacity={opacity(item.index)}
                  className="transition-[fill-opacity] duration-200"
                />
              ))}
            </Bar>
            <KeyboardPoint onChange={setHighlighted} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartActive } from "@/components/charts/bar-chart-active"
```

```tsx
<BarChartActive />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-active.tsx"
import * as React from "react"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  XAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { day: "Monday", steps: 8412 },
  { day: "Tuesday", steps: 10230 },
  { day: "Wednesday", steps: 6120 },
  { day: "Thursday", steps: 12480 },
  { day: "Friday", steps: 9050 },
  { day: "Saturday", steps: 14320 },
  { day: "Sunday", steps: 4870 },
].map((item, index) => ({ ...item, index }))

const chartConfig = {
  steps: { label: "Steps", color: "chart-4" },
} satisfies ChartConfig

function formatSteps(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

export function BarChartActive() {
  const [selected, setSelected] = React.useState(5)
  const day = chartData[selected]
  if (!day) return null

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-orange-500">Steps</Text>
        <View
          className="flex-row items-baseline gap-1"
          accessibilityLiveRegion="polite"
        >
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatSteps(day.steps)}
          </Text>
          <Text className="text-base font-semibold text-muted-foreground">
            steps
          </Text>
        </View>
        <Text className="text-sm text-muted-foreground">
          {`${day.day} · select a bar`}
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Steps"
          className="h-40 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
            onActiveIndexChange={(index) => {
              if (index !== null) setSelected(index)
            }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="day"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <Bar
              dataKey="steps"
              radius={5}
              maxBarSize={28}
              isAnimationActive={false}
            >
              {chartData.map((item) => (
                <Cell
                  key={item.day}
                  fillOpacity={item.index === selected ? 1 : 0.3}
                />
              ))}
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

private let chartData: [(day: String, steps: Double)] = [
  ("Monday", 8412), ("Tuesday", 10230), ("Wednesday", 6120), ("Thursday", 12480),
  ("Friday", 9050), ("Saturday", 14320), ("Sunday", 4870),
]

private let chartConfig: ChartConfig = [
  "steps": .init("Steps", color: EsuissColor.chart4),
]

public struct BarChartActive: View {
  @State private var selected = 5
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init() {}

  private var selection: Binding<Int?> {
    Binding(get: { selected }, set: { if let value = $0 { selected = value } })
  }

  public var body: some View {
    let day = chartData[selected]
    Card(.filled, size: .sm) {
      VStack(alignment: .leading, spacing: 2) {
        Text("Steps")
          .textStyle(.sm, weight: .semibold)
          .foregroundStyle(chartConfig.color("steps"))
        HStack(alignment: .firstTextBaseline, spacing: 4) {
          Text(day.steps, format: .number)
            .textStyle(.xl3, weight: .semibold)
            .monospacedDigit()
          Text("steps")
            .textStyle(.base, weight: .semibold)
            .foregroundStyle(EsuissColor.mutedForeground)
        }
        Text("\(day.day) · select a bar")
          .textStyle(.sm)
          .foregroundStyle(EsuissColor.mutedForeground)
      }
      .padding(.horizontal, 16)
      CardContent {
        ChartContainer(config: chartConfig) {
          Chart {
            ForEach(chartData.indices, id: \.self) { index in
              BarMark(x: .value("Day", chartData[index].day), y: .value("Steps", chartData[index].steps), width: .fixed(28))
                .clipShape(RoundedRectangle(cornerRadius: 5, style: .continuous))
                .foregroundStyle(chartConfig.color("steps").opacity(index == selected ? 1 : 0.3))
            }
          }
          .chartXAxis { ChartAxis.x(values: chartData.map(\.day)) { String($0.prefix(3)) } }
          .chartYAxis { ChartAxis.grid() }
          .animation(reduceMotion ? nil : .easeOut(duration: 0.2), value: selected)
          .chartTooltip(
            x: chartData.map(\.day),
            selection: selection,
            cursor: false,
            accessibilityLabel: "Steps",
            items: { [ChartTooltipItem("steps", value: chartData[$0].steps)] }
          ) { _ in
            EmptyView()
          }
        }
        .frame(height: 160)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartActive.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.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.semantics.LiveRegionMode
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.BarChart
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.ChartCell
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
import java.text.NumberFormat
import java.util.Locale

private class StepsDay(val day: String, val steps: Double)

private val chartData = listOf(
    StepsDay("Monday", 8412.0),
    StepsDay("Tuesday", 10230.0),
    StepsDay("Wednesday", 6120.0),
    StepsDay("Thursday", 12480.0),
    StepsDay("Friday", 9050.0),
    StepsDay("Saturday", 14320.0),
    StepsDay("Sunday", 4870.0),
)

private val chartConfig = ChartConfig(
    "steps" to ChartConfigItem("Steps") { chart4 },
)

@Composable
fun BarChartActive(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    var selected by remember { mutableIntStateOf(5) }
    val day = chartData[selected]
    val stepsFormat = remember { NumberFormat.getNumberInstance(Locale.US) }
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
                BasicText(
                    "Steps",
                    style = Typography.sm.copy(
                        color = if (colors.isDark) colors.chart4 else lerp(colors.chart4, colors.foreground, 0.45f),
                        fontWeight = FontWeight.SemiBold,
                    ),
                )
                Row(
                    Modifier.semantics { liveRegion = LiveRegionMode.Polite },
                    horizontalArrangement = Arrangement.spacedBy(4.dp),
                ) {
                    BasicText(
                        stepsFormat.format(day.steps),
                        Modifier.alignByBaseline(),
                        style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                    )
                    BasicText(
                        "steps",
                        Modifier.alignByBaseline(),
                        style = Typography.base.copy(color = colors.mutedForeground, fontWeight = FontWeight.SemiBold),
                    )
                }
                BasicText("${day.day} · select a bar", style = Typography.sm.copy(color = colors.mutedForeground))
            }
        }
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(160.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    accessibilityLabel = "Steps",
                    selectedIndex = selected,
                    onSelectedIndexChange = { index -> if (index != null) selected = index },
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.day }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    Bar(
                        "steps",
                        value = { it.steps },
                        radius = ChartRadius(5.dp),
                        maxBarSize = 28.dp,
                        cells = { index -> ChartCell(alpha = if (index == selected) 1f else 0.3f) },
                        isAnimationActive = false,
                    )
                }
            }
        }
    }
}
```

**React Native**

Seven bars, one per day, with the selected bar at full opacity and the others dimmed. The `BarChart` reports the touched bar through `onActiveIndexChange`, which updates local state and the header. The header is a live region, so screen readers announce the new step count. The bars set `isAnimationActive={false}` and draw without the enter animation.

Replace `chartData` with your daily values and update the `day` and `steps` keys to match. The initial selection is set by the `useState` default. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-active
```

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 bar-chart-active
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-active
```

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 bar-chart-active --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-active
```

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 bar-chart-active --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/bar-chart-active.tsx`:

- `uniwind/components/charts/bar-chart-active.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/bar-chart-active.tsx`:

```tsx title="nativewind/components/charts/bar-chart-active.tsx"
import * as React from "react"
import { View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  XAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { day: "Monday", steps: 8412 },
  { day: "Tuesday", steps: 10230 },
  { day: "Wednesday", steps: 6120 },
  { day: "Thursday", steps: 12480 },
  { day: "Friday", steps: 9050 },
  { day: "Saturday", steps: 14320 },
  { day: "Sunday", steps: 4870 },
].map((item, index) => ({ ...item, index }))

const chartConfig = {
  steps: { label: "Steps", color: "chart-4" },
} satisfies ChartConfig

function formatSteps(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

export function BarChartActive() {
  const [selected, setSelected] = React.useState(5)
  const day = chartData[selected]
  if (!day) return null

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-orange-500">Steps</Text>
        <View
          className="flex-row items-baseline gap-1"
          accessibilityLiveRegion="polite"
        >
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatSteps(day.steps)}
          </Text>
          <Text className="text-base font-semibold text-muted-foreground">
            steps
          </Text>
        </View>
        <Text className="text-sm text-muted-foreground">
          {`${day.day} · select a bar`}
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Steps"
          className="h-40 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
            onActiveIndexChange={(index) => {
              if (index !== null) setSelected(index)
            }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="day"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <Bar
              dataKey="steps"
              radius={5}
              maxBarSize={28}
              isAnimationActive={false}
            >
              {chartData.map((item) => (
                <Cell
                  key={item.day}
                  fillOpacity={item.index === selected ? 1 : 0.3}
                />
              ))}
            </Bar>
          </BarChart>
        </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/bar-chart-active.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-active.tsx"
import * as React from "react"
import { StyleSheet, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  XAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

const chartData = [
  { day: "Monday", steps: 8412 },
  { day: "Tuesday", steps: 10230 },
  { day: "Wednesday", steps: 6120 },
  { day: "Thursday", steps: 12480 },
  { day: "Friday", steps: 9050 },
  { day: "Saturday", steps: 14320 },
  { day: "Sunday", steps: 4870 },
].map((item, index) => ({ ...item, index }))

const chartConfig = {
  steps: { label: "Steps", color: "chart-4" },
} satisfies ChartConfig

function formatSteps(value: number) {
  try {
    return new Intl.NumberFormat("en-US").format(value)
  } catch {
    return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  }
}

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 },
})

export function BarChartActive() {
  const { colors } = useTheme()
  const [selected, setSelected] = React.useState(5)
  const day = chartData[selected]
  if (!day) return null

  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <Text style={[styles.eyebrow, { color: colors.chart4 }]}>Steps</Text>
        <View style={styles.reading} accessibilityLiveRegion="polite">
          <Text style={styles.value}>{formatSteps(day.steps)}</Text>
          <Text style={[styles.unit, { color: colors.mutedForeground }]}>
            steps
          </Text>
        </View>
        <Text style={[styles.caption, { color: colors.mutedForeground }]}>
          {`${day.day} · select a bar`}
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Steps"
          style={styles.chart}
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
            onActiveIndexChange={(index) => {
              if (index !== null) setSelected(index)
            }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="day"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <Bar
              dataKey="steps"
              radius={5}
              maxBarSize={28}
              isAnimationActive={false}
            >
              {chartData.map((item) => (
                <Cell
                  key={item.day}
                  fillOpacity={item.index === selected ? 1 : 0.3}
                />
              ))}
            </Bar>
          </BarChart>
        </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/BarChartActive.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/BarChartActive.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 { BarChartActive } from "@/components/charts/bar-chart-active"
```

```tsx
<BarChartActive />
```

**SwiftUI**

```swift
import SwiftUI

struct BarActiveExample: View {
  var body: some View {
    BarChartActive()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarActiveExample() {
    BarChartActive()
}
```



## Bar Chart Horizontal

Horizontal bars with category names on the left and a distinct color for each category.

Source: https://suiss.app/ui/docs/charts/bar-chart#horizontal

**React**

**Example**

```tsx title="components/charts/bar-chart-horizontal.tsx"
"use client"

import { Bar, BarChart, 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 = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function BarChartHorizontal() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Horizontal</CardTitle>
        <CardDescription>Room for long category names</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            layout="vertical"
            margin={{ top: 0, right: 8, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="device"
              type="category"
              tickLine={false}
              axisLine={false}
              width="auto"
              tickFormatter={(value: keyof typeof chartConfig) =>
                String(chartConfig[value]?.label)
              }
            />
            <XAxis type="number" hide />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Bar dataKey="users" radius={5} barSize={18} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Horizontal bars with category names down the left and a different color per category. Choose it over vertical bars when labels are long or when you are ranking items.

Give each record a category key, a value and a `fill` that points at its color variable, and add a label and color for each key to `chartConfig`. The left axis reads its text from those labels and sizes itself to the longest one, and `barSize` sets the bar thickness. Focus the chart and use the arrow keys to move the tooltip between bars.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-horizontal
```

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 bar-chart-horizontal
```

**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/bar-chart-horizontal.tsx"
"use client"

import { Bar, BarChart, 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 = [
  { device: "phone", users: 275, fill: "var(--color-phone)" },
  { device: "laptop", users: 200, fill: "var(--color-laptop)" },
  { device: "tablet", users: 187, fill: "var(--color-tablet)" },
  { device: "watch", users: 173, fill: "var(--color-watch)" },
  { device: "other", users: 90, fill: "var(--color-other)" },
]

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "var(--chart-1)" },
  laptop: { label: "Laptop", color: "var(--chart-2)" },
  tablet: { label: "Tablet", color: "var(--chart-3)" },
  watch: { label: "Watch", color: "var(--chart-4)" },
  other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig

export function BarChartHorizontal() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Horizontal</CardTitle>
        <CardDescription>Room for long category names</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            layout="vertical"
            margin={{ top: 0, right: 8, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="device"
              type="category"
              tickLine={false}
              axisLine={false}
              width="auto"
              tickFormatter={(value: keyof typeof chartConfig) =>
                String(chartConfig[value]?.label)
              }
            />
            <XAxis type="number" hide />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Bar dataKey="users" radius={5} barSize={18} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartHorizontal } from "@/components/charts/bar-chart-horizontal"
```

```tsx
<BarChartHorizontal />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-horizontal.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

type Device = "phone" | "laptop" | "tablet" | "watch" | "other"

const chartData: { device: Device; users: number }[] = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

export function BarChartHorizontal() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Horizontal</CardTitle>
        <CardDescription>Room for long category names</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Horizontal"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            layout="vertical"
            margin={{ top: 0, right: 8, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="device"
              type="category"
              width="auto"
              tickFormatter={(value) => chartConfig[value as Device].label}
            />
            <XAxis type="number" hide />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Bar dataKey="users" radius={5} barSize={18}>
              {chartData.map((item) => (
                <Cell key={item.device} fill={chartConfig[item.device].color} />
              ))}
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

private let chartData: [(device: String, users: Double)] = [
  ("phone", 275), ("laptop", 200), ("tablet", 187), ("watch", 173), ("other", 90),
]

private let chartConfig: ChartConfig = [
  "users": .init("Users"),
  "phone": .init("Phone", color: EsuissColor.chart1),
  "laptop": .init("Laptop", color: EsuissColor.chart2),
  "tablet": .init("Tablet", color: EsuissColor.chart3),
  "watch": .init("Watch", color: EsuissColor.chart4),
  "other": .init("Other", color: EsuissColor.chart5),
]

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

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Horizontal", description: "Room for long category names")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                BarMark(x: .value("Users", chartData[index].users * progress), y: .value("Device", chartData[index].device), height: .fixed(18))
                  .clipShape(RoundedRectangle(cornerRadius: 5, style: .continuous))
                  .foregroundStyle(chartConfig.color(chartData[index].device))
                ChartAnchorMark(x: .value("Users", chartData[index].users), y: .value("Device", chartData[index].device))
              }
            }
            .chartXScale(range: .plotDimension(endPadding: 8))
            .chartXAxis(.hidden)
            .chartYAxis { ChartAxis.y(values: chartData.map(\.device), edge: .leading, grid: false) { chartConfig.label($0) } }
            .chartTooltip(
              y: chartData.map(\.device),
              labels: chartData.map { chartConfig.label($0.device) },
              selection: $selection,
              accessibilityLabel: "Horizontal",
              items: { [ChartTooltipItem(chartData[$0].device, value: chartData[$0].users)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartHorizontal.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.BarChart
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.ChartLayout
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent

private class DeviceUsers(val device: String, val users: Double)

private val chartData = listOf(
    DeviceUsers("phone", 275.0),
    DeviceUsers("laptop", 200.0),
    DeviceUsers("tablet", 187.0),
    DeviceUsers("watch", 173.0),
    DeviceUsers("other", 90.0),
)

private val chartConfig = ChartConfig(
    "users" to ChartConfigItem("Users"),
    "phone" to ChartConfigItem("Phone") { chart1 },
    "laptop" to ChartConfigItem("Laptop") { chart2 },
    "tablet" to ChartConfigItem("Tablet") { chart3 },
    "watch" to ChartConfigItem("Watch") { chart4 },
    "other" to ChartConfigItem("Other") { chart5 },
)

@Composable
fun BarChartHorizontal(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Horizontal", description = "Room for long category names")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                BarChart(
                    chartData,
                    layout = ChartLayout.Vertical,
                    margin = ChartMargin(top = 0.dp, right = 8.dp, bottom = 0.dp, left = 0.dp),
                    accessibilityLabel = "Horizontal",
                ) {
                    YAxis(label = { it.device }, tickFormatter = { chartConfig[it]?.label ?: it })
                    ChartTooltip(cursor = null) { ChartTooltipContent(hideLabel = true) }
                    Bar("users", value = { it.users }, nameKey = { it.device }, radius = ChartRadius(5.dp), barSize = 18.dp)
                }
            }
        }
    }
}
```

**React Native**

A `BarChart` with `layout="vertical"`, so categories run down a `YAxis` and bars extend to the right, which leaves room for longer names. Each bar gets its color from `chartConfig` through a `Cell`, and the axis labels come from the same config.

Replace `chartData` with your categories and values, and add a matching entry with a label and color to `chartConfig` for each category. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-horizontal
```

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 bar-chart-horizontal
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-horizontal
```

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 bar-chart-horizontal --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-horizontal
```

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 bar-chart-horizontal --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/bar-chart-horizontal.tsx`:

- `uniwind/components/charts/bar-chart-horizontal.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/bar-chart-horizontal.tsx`:

```tsx title="nativewind/components/charts/bar-chart-horizontal.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

type Device = "phone" | "laptop" | "tablet" | "watch" | "other"

const chartData: { device: Device; users: number }[] = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

export function BarChartHorizontal() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Horizontal</CardTitle>
        <CardDescription>Room for long category names</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Horizontal"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            layout="vertical"
            margin={{ top: 0, right: 8, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="device"
              type="category"
              width="auto"
              tickFormatter={(value) => chartConfig[value as Device].label}
            />
            <XAxis type="number" hide />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Bar dataKey="users" radius={5} barSize={18}>
              {chartData.map((item) => (
                <Cell key={item.device} fill={chartConfig[item.device].color} />
              ))}
            </Bar>
          </BarChart>
        </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/bar-chart-horizontal.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-horizontal.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"

const chartConfig = {
  users: { label: "Users" },
  phone: { label: "Phone", color: "chart-1" },
  laptop: { label: "Laptop", color: "chart-2" },
  tablet: { label: "Tablet", color: "chart-3" },
  watch: { label: "Watch", color: "chart-4" },
  other: { label: "Other", color: "chart-5" },
} satisfies ChartConfig

type Device = "phone" | "laptop" | "tablet" | "watch" | "other"

const chartData: { device: Device; users: number }[] = [
  { device: "phone", users: 275 },
  { device: "laptop", users: 200 },
  { device: "tablet", users: 187 },
  { device: "watch", users: 173 },
  { device: "other", users: 90 },
]

export function BarChartHorizontal() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Horizontal</CardTitle>
        <CardDescription>Room for long category names</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Horizontal"
          style={{ height: 192 }}
        >
          <BarChart
            data={chartData}
            layout="vertical"
            margin={{ top: 0, right: 8, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="device"
              type="category"
              width="auto"
              tickFormatter={(value) => chartConfig[value as Device].label}
            />
            <XAxis type="number" hide />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel nameKey="device" />}
            />
            <Bar dataKey="users" radius={5} barSize={18}>
              {chartData.map((item) => (
                <Cell key={item.device} fill={chartConfig[item.device].color} />
              ))}
            </Bar>
          </BarChart>
        </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/BarChartHorizontal.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/BarChartHorizontal.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 { BarChartHorizontal } from "@/components/charts/bar-chart-horizontal"
```

```tsx
<BarChartHorizontal />
```

**SwiftUI**

```swift
import SwiftUI

struct BarHorizontalExample: View {
  var body: some View {
    BarChartHorizontal()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarHorizontalExample() {
    BarChartHorizontal()
}
```



## Bar Chart Hourly

Twenty-four thin bars of screen time per hour, with a dashed line marking the hourly average.

Source: https://suiss.app/ui/docs/charts/bar-chart#hourly

**React**

**Example**

```tsx title="components/charts/bar-chart-hourly.tsx"
"use client"

import {
  Bar,
  BarChart,
  CartesianGrid,
  ReferenceLine,
  XAxis,
  YAxis,
} from "recharts"

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

const chartData = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42,
  47, 35, 18,
].map((minutes, hour) => ({ hour, minutes }))

const chartConfig = {
  minutes: { label: "Screen time", color: "var(--chart-1)" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.minutes, 0)
const average = total / chartData.length

export function BarChartHourly() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-primary">Screen time</p>
        <p className="text-3xl font-semibold tracking-tight tabular-nums">
          {Math.floor(total / 60)}h {total % 60}m
        </p>
        <p className="text-sm text-muted-foreground">Today · hour by hour</p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              ticks={[0, 6, 12, 18]}
              interval={0}
              tickFormatter={(value: number) => `${value}:00`}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              tickCount={3}
              tickFormatter={(value: number) => `${value} min`}
            />
            <ReferenceLine
              y={average}
              stroke="var(--color-green-500)"
              strokeDasharray="3 3"
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  labelFormatter={(_, payload) =>
                    `${payload[0]?.payload.hour}:00`
                  }
                  formatter={(value) => (
                    <span className="font-semibold tabular-nums">
                      {value} min
                    </span>
                  )}
                />
              }
            />
            <Bar
              dataKey="minutes"
              fill="var(--color-minutes)"
              radius={[3, 3, 0, 0]}
              maxBarSize={8}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A screen-time card with 24 thin hourly bars, a total in the header and a dashed line at the hourly average. Use it for any day-at-a-glance metric with many small periods.

Replace the 24 values in `chartData`; the total and the average line are computed from them. Change the axis `ticks` to label other hours, and update the minute unit in the axis, tooltip and header if you measure something else. With 24 narrow bars the tooltip is the most reliable readout; focus the chart and use the arrow keys to step through the hours.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-hourly
```

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 bar-chart-hourly
```

**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/bar-chart-hourly.tsx"
"use client"

import {
  Bar,
  BarChart,
  CartesianGrid,
  ReferenceLine,
  XAxis,
  YAxis,
} from "recharts"

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

const chartData = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42,
  47, 35, 18,
].map((minutes, hour) => ({ hour, minutes }))

const chartConfig = {
  minutes: { label: "Screen time", color: "var(--chart-1)" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.minutes, 0)
const average = total / chartData.length

export function BarChartHourly() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <p className="text-sm font-semibold text-primary">Screen time</p>
        <p className="text-3xl font-semibold tracking-tight tabular-nums">
          {Math.floor(total / 60)}h {total % 60}m
        </p>
        <p className="text-sm text-muted-foreground">Today · hour by hour</p>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-40 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              ticks={[0, 6, 12, 18]}
              interval={0}
              tickFormatter={(value: number) => `${value}:00`}
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              tickCount={3}
              tickFormatter={(value: number) => `${value} min`}
            />
            <ReferenceLine
              y={average}
              stroke="var(--color-green-500)"
              strokeDasharray="3 3"
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  labelFormatter={(_, payload) =>
                    `${payload[0]?.payload.hour}:00`
                  }
                  formatter={(value) => (
                    <span className="font-semibold tabular-nums">
                      {value} min
                    </span>
                  )}
                />
              }
            />
            <Bar
              dataKey="minutes"
              fill="var(--color-minutes)"
              radius={[3, 3, 0, 0]}
              maxBarSize={8}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartHourly } from "@/components/charts/bar-chart-hourly"
```

```tsx
<BarChartHourly />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-hourly.tsx"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42,
  47, 35, 18,
].map((minutes, hour) => ({ hour, minutes }))

const chartConfig = {
  minutes: { label: "Screen time", color: "chart-1" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.minutes, 0)
const average = total / chartData.length

export function BarChartHourly() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-primary">Screen time</Text>
        <Text className="text-3xl font-semibold tracking-tight tabular-nums">
          {`${Math.floor(total / 60)}h ${total % 60}m`}
        </Text>
        <Text className="text-sm text-muted-foreground">
          Today · hour by hour
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          className="h-40 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickMargin={8}
              ticks={[0, 6, 12, 18]}
              interval={0}
              tickFormatter={(value) => `${value}:00`}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={3}
              tickFormatter={(value) => `${value} min`}
            />
            <ReferenceLine
              y={average}
              stroke="green-500"
              strokeDasharray="3 3"
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  labelFormatter={(_, payload) =>
                    `${String(payload[0]?.payload.hour)}:00`
                  }
                  formatter={(value) => (
                    <Text className="font-semibold tabular-nums">
                      {`${String(value)} min`}
                    </Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="minutes"
              fill="chart-1"
              radius={[3, 3, 0, 0]}
              maxBarSize={8}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

private let minutes: [Double] = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42, 47, 35, 18,
]

private let hours = minutes.indices.map { "\($0)" }

private let chartConfig: ChartConfig = [
  "minutes": .init("Screen time", color: EsuissColor.chart1),
]

private let total = Int(minutes.reduce(0, +))
private let average = minutes.reduce(0, +) / Double(minutes.count)

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

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      VStack(alignment: .leading, spacing: 2) {
        Text("Screen time")
          .textStyle(.sm, weight: .semibold)
          .foregroundStyle(EsuissColor.primary)
        Text(verbatim: "\(total / 60)h \(total % 60)m")
          .textStyle(.xl3, weight: .semibold)
          .monospacedDigit()
        Text("Today · hour by hour")
          .textStyle(.sm)
          .foregroundStyle(EsuissColor.mutedForeground)
      }
      .padding(.horizontal, 16)
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(minutes.indices, id: \.self) { hour in
                BarMark(x: .value("Hour", hours[hour]), y: .value("Minutes", minutes[hour] * progress), width: .fixed(8))
                  .clipShape(UnevenRoundedRectangle(topLeadingRadius: 3, topTrailingRadius: 3, style: .continuous))
                  .foregroundStyle(chartConfig.color("minutes"))
                ChartAnchorMark(x: .value("Hour", hours[hour]), y: .value("Minutes", minutes[hour]))
              }
              RuleMark(y: .value("Average", average))
                .lineStyle(StrokeStyle(lineWidth: 1, dash: [3, 3]))
                .foregroundStyle(Palette.green500)
            }
            .chartXAxis { ChartAxis.x(values: ["0", "6", "12", "18"]) { "\($0):00" } }
            .chartYAxis { ChartAxis.y(count: 3) { "\(Int($0)) min" } }
            .chartTooltip(
              x: hours,
              labels: hours.map { "\($0):00" },
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Screen time",
              items: { [ChartTooltipItem("minutes", value: minutes[$0])] }
            ) { payload in
              ChartTooltipContent(payload, hideIndicator: true) { payload in
                Text(verbatim: payload.label)
              } formatter: { item in
                Text("\(Int(item.value)) min")
                  .scaledFont(TextStyle.xs, weight: .semibold)
                  .monospacedDigit()
              }
            }
          }
        }
        .frame(height: 160)
      }
    }
  }
}
```

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

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
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.BarChart
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.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Typography

private class HourMinutes(val hour: Int, val minutes: Int)

private val chartData = listOf(
    4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42, 47, 35, 18,
).mapIndexed { hour, minutes -> HourMinutes(hour, minutes) }

private val chartConfig = ChartConfig(
    "minutes" to ChartConfigItem("Screen time") { chart1 },
)

private val total = chartData.sumOf { it.minutes }

private val average = total.toDouble() / chartData.size

@Composable
fun BarChartHourly(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
                BasicText("Screen time", style = Typography.sm.copy(color = colors.primary, fontWeight = FontWeight.SemiBold))
                BasicText(
                    "${total / 60}h ${total % 60}m",
                    style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                )
                BasicText("Today · hour by hour", style = Typography.sm.copy(color = colors.mutedForeground))
            }
        }
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(160.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 12.dp),
                    accessibilityLabel = "Screen time",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { "${it.hour}" }, tickMargin = 8.dp, interval = 0, ticks = listOf(0, 6, 12, 18), tickFormatter = { "$it:00" })
                    YAxis(
                        orientation = ChartAxisOrientation.Right,
                        tickMargin = 6.dp,
                        tickCount = 3,
                        tickFormatter = { "${it.toInt()} min" },
                    )
                    ReferenceLine(average, stroke = Palette.green500, strokeDasharray = listOf(3f, 3f))
                    ChartTooltip(cursor = null) {
                        ChartTooltipContent(
                            hideIndicator = true,
                            labelFormatter = { label, _ ->
                                BasicText("$label:00", style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold))
                            },
                            formatter = { item ->
                                BasicText(
                                    "${item.value.toInt()} min",
                                    style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                                )
                            },
                        )
                    }
                    Bar(
                        "minutes",
                        value = { it.minutes.toDouble() },
                        radius = ChartRadius(3.dp, 3.dp, 0.dp, 0.dp),
                        maxBarSize = 8.dp,
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

Thin bars show minutes for each hour of the day, with ticks every six hours and a value axis in minutes on the right. A `ReferenceLine` marks the hourly average, and the header shows the day's total in hours and minutes. The tooltip formats the hour and the minutes.

**React Native**

Replace the 24 values in `chartData` with your hourly minutes; the total and average are calculated from it. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-hourly
```

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 bar-chart-hourly
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-hourly
```

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 bar-chart-hourly --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-hourly
```

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 bar-chart-hourly --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/bar-chart-hourly.tsx`:

- `uniwind/components/charts/bar-chart-hourly.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/bar-chart-hourly.tsx`:

```tsx title="nativewind/components/charts/bar-chart-hourly.tsx"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42,
  47, 35, 18,
].map((minutes, hour) => ({ hour, minutes }))

const chartConfig = {
  minutes: { label: "Screen time", color: "chart-1" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.minutes, 0)
const average = total / chartData.length

export function BarChartHourly() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader className="gap-0.5">
        <Text className="text-sm font-semibold text-primary">Screen time</Text>
        <Text className="text-3xl font-semibold tracking-tight tabular-nums">
          {`${Math.floor(total / 60)}h ${total % 60}m`}
        </Text>
        <Text className="text-sm text-muted-foreground">
          Today · hour by hour
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          className="h-40 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickMargin={8}
              ticks={[0, 6, 12, 18]}
              interval={0}
              tickFormatter={(value) => `${value}:00`}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={3}
              tickFormatter={(value) => `${value} min`}
            />
            <ReferenceLine
              y={average}
              stroke="green-500"
              strokeDasharray="3 3"
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  labelFormatter={(_, payload) =>
                    `${String(payload[0]?.payload.hour)}:00`
                  }
                  formatter={(value) => (
                    <Text className="font-semibold tabular-nums">
                      {`${String(value)} min`}
                    </Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="minutes"
              fill="chart-1"
              radius={[3, 3, 0, 0]}
              maxBarSize={8}
            />
          </BarChart>
        </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/bar-chart-hourly.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-hourly.tsx"
import { StyleSheet } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

const chartData = [
  4, 0, 0, 0, 0, 0, 6, 18, 27, 22, 19, 21, 30, 26, 23, 17, 22, 26, 31, 39, 42,
  47, 35, 18,
].map((minutes, hour) => ({ hour, minutes }))

const chartConfig = {
  minutes: { label: "Screen time", color: "chart-1" },
} satisfies ChartConfig

const total = chartData.reduce((sum, item) => sum + item.minutes, 0)
const average = total / chartData.length

const styles = StyleSheet.create({
  header: { gap: 2 },
  eyebrow: { ...fontSize.sm, fontWeight: "600" },
  value: {
    ...fontSize["3xl"],
    fontWeight: "600",
    letterSpacing: -0.75,
    fontVariant: ["tabular-nums"],
  },
  caption: { ...fontSize.sm },
  strong: { fontWeight: "600", fontVariant: ["tabular-nums"] },
  chart: { height: 160 },
})

export function BarChartHourly() {
  const { colors } = useTheme()
  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <Text style={[styles.eyebrow, { color: colors.primary }]}>
          Screen time
        </Text>
        <Text style={styles.value}>
          {`${Math.floor(total / 60)}h ${total % 60}m`}
        </Text>
        <Text style={[styles.caption, { color: colors.mutedForeground }]}>
          Today · hour by hour
        </Text>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          style={styles.chart}
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="hour"
              tickMargin={8}
              ticks={[0, 6, 12, 18]}
              interval={0}
              tickFormatter={(value) => `${value}:00`}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              tickCount={3}
              tickFormatter={(value) => `${value} min`}
            />
            <ReferenceLine
              y={average}
              stroke="green-500"
              strokeDasharray="3 3"
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  labelFormatter={(_, payload) =>
                    `${String(payload[0]?.payload.hour)}:00`
                  }
                  formatter={(value) => (
                    <Text style={styles.strong}>{`${String(value)} min`}</Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="minutes"
              fill="chart-1"
              radius={[3, 3, 0, 0]}
              maxBarSize={8}
            />
          </BarChart>
        </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/BarChartHourly.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/BarChartHourly.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 { BarChartHourly } from "@/components/charts/bar-chart-hourly"
```

```tsx
<BarChartHourly />
```

**SwiftUI**

```swift
import SwiftUI

struct BarHourlyExample: View {
  var body: some View {
    BarChartHourly()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarHourlyExample() {
    BarChartHourly()
}
```



## Bar Chart Interactive

A screen-time report with stacked category bars, a week and day toggle, selectable days and a most-used apps list.

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

**React**

**Example**

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

import * as React from "react"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  ReferenceLine,
  useActiveTooltipDataPoints,
  XAxis,
  YAxis,
} from "recharts"

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

type Category = "social" | "productivity" | "entertainment"

const CATEGORIES: Category[] = ["social", "productivity", "entertainment"]

const DAYS = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
]

const USAGE: [social: number, productivity: number, entertainment: number][] = [
  [48, 95, 62],
  [55, 120, 40],
  [70, 88, 95],
  [42, 130, 35],
  [65, 100, 80],
  [110, 30, 140],
  [95, 25, 120],
]

const WEEK: Record<Category, number>[] = USAGE.map(
  ([social, productivity, entertainment]) => ({
    social,
    productivity,
    entertainment,
  })
)

const PROFILE = [
  1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4,
]

const APPS: { name: string; category: Category; share: number }[] = [
  { name: "Chat", category: "social", share: 0.55 },
  { name: "Messages", category: "social", share: 0.45 },
  { name: "Browser", category: "productivity", share: 0.45 },
  { name: "Mail", category: "productivity", share: 0.3 },
  { name: "Docs", category: "productivity", share: 0.25 },
  { name: "Video", category: "entertainment", share: 0.6 },
  { name: "Music", category: "entertainment", share: 0.4 },
]

const chartConfig = {
  social: { label: "Social", color: "var(--chart-1)" },
  productivity: { label: "Productivity", color: "var(--color-cyan-500)" },
  entertainment: { label: "Entertainment", color: "var(--chart-4)" },
} satisfies ChartConfig

const total = (day: Record<Category, number>) =>
  CATEGORIES.reduce((sum, category) => sum + day[category], 0)

const TAP_SLOP = 10

const AVERAGE = WEEK.reduce((sum, day) => sum + total(day), 0) / WEEK.length

const DAILY_AVERAGE = Object.fromEntries(
  CATEGORIES.map((category) => [
    category,
    WEEK.reduce((sum, day) => sum + day[category], 0) / WEEK.length,
  ])
) as Record<Category, number>

function formatMinutes(minutes: number) {
  const rounded = Math.round(minutes)
  const hours = Math.floor(rounded / 60)
  return hours ? `${hours}h ${rounded % 60}m` : `${rounded}m`
}

function noise(seed: number) {
  const state = (seed * 16807) % 2147483647
  return (state - 1) / 2147483646
}

function distribute(amount: number, weights: number[]) {
  const sum = weights.reduce((total, weight) => total + weight, 0)
  const exact = weights.map((weight) => (sum ? (amount * weight) / sum : 0))
  const parts = exact.map(Math.floor)
  let rest = amount - parts.reduce((total, part) => total + part, 0)
  const order = exact
    .map((value, index) => ({ index, remainder: value - Math.floor(value) }))
    .sort((a, b) => b.remainder - a.remainder)
  for (const { index } of order) {
    if (rest <= 0) break
    parts[index] = (parts[index] ?? 0) + 1
    rest -= 1
  }
  return parts
}

function hourly(day: number) {
  const categories = WEEK[day]
  if (!categories) return []
  const base = PROFILE.map(
    (weight, hour) => weight * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
  )
  const social = distribute(categories.social, base)
  const productivity = distribute(
    categories.productivity,
    base.map((weight, hour) => weight * (hour > 8 && hour < 18 ? 1.6 : 0.4))
  )
  const entertainment = distribute(
    categories.entertainment,
    base.map((weight, hour) => weight * (hour > 18 ? 1.8 : 0.5))
  )
  return PROFILE.map((_, hour) => ({
    label: String(hour),
    index: hour,
    social: social[hour] ?? 0,
    productivity: productivity[hour] ?? 0,
    entertainment: entertainment[hour] ?? 0,
  }))
}

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

  React.useEffect(() => {
    if (index !== null) onChange(index)
  }, [index, onChange])

  return null
}

export function BarChartInteractive() {
  const [view, setView] = React.useState<"week" | "day">("week")
  const [selected, setSelected] = React.useState<number | null>(null)
  const [highlighted, setHighlighted] = React.useState<number | null>(null)
  const [hoveredApp, setHoveredApp] = React.useState<string | null>(null)
  const touchRef = React.useRef<{ x: number; y: number } | null>(null)

  const isWeek = view === "week"
  const selectedDay = selected === null ? undefined : WEEK[selected]
  const categories = selectedDay ?? DAILY_AVERAGE
  const headline = selectedDay ? total(selectedDay) : AVERAGE
  const data = isWeek
    ? WEEK.map((day, index) => ({
        ...day,
        label: DAYS[index]?.slice(0, 3) ?? "",
        index,
      }))
    : hourly(selected ?? 6)
  const apps = APPS.map((app) => ({
    ...app,
    minutes: categories[app.category] * app.share,
  }))
    .sort((a, b) => b.minutes - a.minutes)
    .slice(0, 5)
  const longest = Math.max(...apps.map((app) => app.minutes))
  const comparison =
    selected === null
      ? "8% less than last week"
      : `${Math.round(Math.abs(headline / AVERAGE - 1) * 100)}% ${headline > AVERAGE ? "above" : "below"} average`

  const select = (index: number) => {
    if (!isWeek) return
    setSelected((current) => (current === index ? null : index))
  }

  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-52 flex-1 flex-col gap-0.5"
          aria-live="polite"
        >
          <p className="text-sm font-semibold text-muted-foreground">
            {selected === null ? "Daily average" : DAYS[selected]}
          </p>
          <p className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatMinutes(headline)}
          </p>
          <p className="text-sm text-muted-foreground">{comparison}</p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[view]}
          onValueChange={(value: string[]) => {
            const next = value[0] as "week" | "day" | undefined
            if (!next) return
            setView(next)
            if (next === "day" && selected === null) setSelected(6)
          }}
          aria-label="Period"
        >
          <ToggleGroupItem value="week" size="sm" className="px-5">
            Week
          </ToggleGroupItem>
          <ToggleGroupItem value="day" size="sm" className="px-5">
            Day
          </ToggleGroupItem>
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-5">
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-64 w-full data-[view=week]:[&_.recharts-bar-rectangle]:cursor-pointer"
          data-view={view}
          onKeyDown={(event) => {
            if (
              (event.key === "Enter" || event.key === " ") &&
              highlighted !== null
            ) {
              event.preventDefault()
              select(highlighted)
            }
          }}
          onBlur={(event) => {
            if (!event.currentTarget.contains(event.relatedTarget)) {
              setHighlighted(null)
            }
          }}
        >
          <BarChart
            accessibilityLayer
            data={data}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="label"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              ticks={isWeek ? undefined : ["0", "6", "12", "18"]}
              tickFormatter={(value: string) =>
                isWeek ? value : `${value}:00`
              }
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              ticks={isWeek ? [0, 120, 240, 360] : undefined}
              tickCount={isWeek ? undefined : 4}
              tickFormatter={(value: number) =>
                isWeek ? `${value / 60}h` : `${value}m`
              }
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  labelFormatter={(_, payload) => {
                    const label = payload[0]?.payload.label
                    return isWeek
                      ? DAYS[DAYS.findIndex((day) => day.startsWith(label))]
                      : `${label}:00 – ${Number(label) + 1}:00`
                  }}
                  formatter={(value, name) => (
                    <div className="flex w-full items-center gap-2">
                      <span
                        className="size-2 shrink-0 rounded-xs bg-(--swatch)"
                        style={
                          {
                            "--swatch": `var(--color-${name})`,
                          } as React.CSSProperties
                        }
                      />
                      <span className="flex-1 text-muted-foreground">
                        {chartConfig[name as Category].label}
                      </span>
                      <span className="font-semibold tabular-nums">
                        {formatMinutes(Number(value))}
                      </span>
                    </div>
                  )}
                />
              }
            />
            {isWeek && (
              <ReferenceLine
                y={AVERAGE}
                stroke="var(--color-green-500)"
                strokeDasharray="3 3"
              />
            )}
            {CATEGORIES.map((category, position) => (
              <Bar
                key={category}
                dataKey={category}
                stackId="a"
                fill={`var(--color-${category})`}
                radius={position === CATEGORIES.length - 1 ? [5, 5, 0, 0] : 0}
                maxBarSize={isWeek ? 34 : 10}
                isAnimationActive={false}
                onClick={(_, index) => select(index)}
                onTouchStart={(_, __, event) => {
                  const touch = event.touches[0]
                  if (!touch) return
                  touchRef.current = { x: touch.clientX, y: touch.clientY }
                }}
                onTouchEnd={(_, index, event) => {
                  const start = touchRef.current
                  const touch = event.changedTouches[0]
                  touchRef.current = null
                  if (
                    !start ||
                    !touch ||
                    Math.hypot(
                      touch.clientX - start.x,
                      touch.clientY - start.y
                    ) > TAP_SLOP
                  )
                    return
                  event.preventDefault()
                  select(index)
                }}
              >
                {isWeek &&
                  data.map((item, index) => (
                    <Cell
                      key={String(item.label)}
                      fillOpacity={
                        selected === null || selected === index ? 1 : 0.3
                      }
                      className="transition-[fill-opacity] duration-200"
                    />
                  ))}
              </Bar>
            ))}
            <KeyboardPoint onChange={setHighlighted} />
          </BarChart>
        </ChartContainer>
        <dl className="grid grid-cols-3 gap-3">
          {CATEGORIES.map((category) => (
            <div key={category} className="flex min-w-0 flex-col gap-0.5">
              <dt className="flex min-w-0 items-center gap-1.5 text-sm text-muted-foreground">
                <span
                  className="size-2 shrink-0 rounded-full bg-(--swatch)"
                  style={
                    {
                      "--swatch": chartConfig[category].color,
                    } as React.CSSProperties
                  }
                />
                <span className="truncate">{chartConfig[category].label}</span>
              </dt>
              <dd className="text-base font-semibold tabular-nums">
                {formatMinutes(categories[category])}
              </dd>
            </div>
          ))}
        </dl>
        <div className="flex flex-col">
          <p className="mb-1 text-xs font-semibold text-muted-foreground uppercase">
            Most used
          </p>
          <ul>
            {apps.map((app) => (
              <li
                key={app.name}
                onPointerEnter={() => setHoveredApp(app.name)}
                onPointerLeave={() => setHoveredApp(null)}
                className="grid grid-cols-[6rem_1fr_4.5rem] items-center gap-3 border-t border-border py-2"
              >
                <span className="truncate text-base">{app.name}</span>
                <span className="h-1.5 overflow-hidden rounded-full bg-secondary">
                  <span
                    data-dimmed={
                      hoveredApp !== null && hoveredApp !== app.name
                        ? ""
                        : undefined
                    }
                    className="block h-full origin-left rounded-full rtl:origin-right bg-(--swatch) transition-[scale,opacity] duration-400 ease-[cubic-bezier(0.32,0.72,0,1)] data-dimmed:opacity-40"
                    style={
                      {
                        "--swatch": chartConfig[app.category].color,
                        scale: `${app.minutes / longest} 1`,
                      } as React.CSSProperties
                    }
                  />
                </span>
                <span className="text-end text-sm text-muted-foreground tabular-nums">
                  {formatMinutes(app.minutes)}
                </span>
              </li>
            ))}
          </ul>
        </div>
      </CardContent>
    </Card>
  )
}
```

A full screen-time report: stacked category bars per day, a Week and Day toggle, selectable days, per-category totals and a most-used apps list that all update together. Use it as a reference for building a drill-down dashboard on top of a bar chart.

Replace `USAGE` with your per-day category totals and `APPS` with your item breakdown, and rename the categories in `CATEGORIES` and `chartConfig`. The hourly Day view is generated from the daily totals for the demo, and the comparison line is a fixed string until a day is selected. Click, tap or press Return on a bar to select a day, and select it again to clear it; taps that move like a scroll are ignored. Day view shows Sunday when no day is selected, and the header announces changes through a live region.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-interactive.tsx"
"use client"

import * as React from "react"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  ReferenceLine,
  useActiveTooltipDataPoints,
  XAxis,
  YAxis,
} from "recharts"

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

type Category = "social" | "productivity" | "entertainment"

const CATEGORIES: Category[] = ["social", "productivity", "entertainment"]

const DAYS = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
]

const USAGE: [social: number, productivity: number, entertainment: number][] = [
  [48, 95, 62],
  [55, 120, 40],
  [70, 88, 95],
  [42, 130, 35],
  [65, 100, 80],
  [110, 30, 140],
  [95, 25, 120],
]

const WEEK: Record<Category, number>[] = USAGE.map(
  ([social, productivity, entertainment]) => ({
    social,
    productivity,
    entertainment,
  })
)

const PROFILE = [
  1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4,
]

const APPS: { name: string; category: Category; share: number }[] = [
  { name: "Chat", category: "social", share: 0.55 },
  { name: "Messages", category: "social", share: 0.45 },
  { name: "Browser", category: "productivity", share: 0.45 },
  { name: "Mail", category: "productivity", share: 0.3 },
  { name: "Docs", category: "productivity", share: 0.25 },
  { name: "Video", category: "entertainment", share: 0.6 },
  { name: "Music", category: "entertainment", share: 0.4 },
]

const chartConfig = {
  social: { label: "Social", color: "var(--chart-1)" },
  productivity: { label: "Productivity", color: "var(--color-cyan-500)" },
  entertainment: { label: "Entertainment", color: "var(--chart-4)" },
} satisfies ChartConfig

const total = (day: Record<Category, number>) =>
  CATEGORIES.reduce((sum, category) => sum + day[category], 0)

const TAP_SLOP = 10

const AVERAGE = WEEK.reduce((sum, day) => sum + total(day), 0) / WEEK.length

const DAILY_AVERAGE = Object.fromEntries(
  CATEGORIES.map((category) => [
    category,
    WEEK.reduce((sum, day) => sum + day[category], 0) / WEEK.length,
  ])
) as Record<Category, number>

function formatMinutes(minutes: number) {
  const rounded = Math.round(minutes)
  const hours = Math.floor(rounded / 60)
  return hours ? `${hours}h ${rounded % 60}m` : `${rounded}m`
}

function noise(seed: number) {
  const state = (seed * 16807) % 2147483647
  return (state - 1) / 2147483646
}

function distribute(amount: number, weights: number[]) {
  const sum = weights.reduce((total, weight) => total + weight, 0)
  const exact = weights.map((weight) => (sum ? (amount * weight) / sum : 0))
  const parts = exact.map(Math.floor)
  let rest = amount - parts.reduce((total, part) => total + part, 0)
  const order = exact
    .map((value, index) => ({ index, remainder: value - Math.floor(value) }))
    .sort((a, b) => b.remainder - a.remainder)
  for (const { index } of order) {
    if (rest <= 0) break
    parts[index] = (parts[index] ?? 0) + 1
    rest -= 1
  }
  return parts
}

function hourly(day: number) {
  const categories = WEEK[day]
  if (!categories) return []
  const base = PROFILE.map(
    (weight, hour) => weight * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
  )
  const social = distribute(categories.social, base)
  const productivity = distribute(
    categories.productivity,
    base.map((weight, hour) => weight * (hour > 8 && hour < 18 ? 1.6 : 0.4))
  )
  const entertainment = distribute(
    categories.entertainment,
    base.map((weight, hour) => weight * (hour > 18 ? 1.8 : 0.5))
  )
  return PROFILE.map((_, hour) => ({
    label: String(hour),
    index: hour,
    social: social[hour] ?? 0,
    productivity: productivity[hour] ?? 0,
    entertainment: entertainment[hour] ?? 0,
  }))
}

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

  React.useEffect(() => {
    if (index !== null) onChange(index)
  }, [index, onChange])

  return null
}

export function BarChartInteractive() {
  const [view, setView] = React.useState<"week" | "day">("week")
  const [selected, setSelected] = React.useState<number | null>(null)
  const [highlighted, setHighlighted] = React.useState<number | null>(null)
  const [hoveredApp, setHoveredApp] = React.useState<string | null>(null)
  const touchRef = React.useRef<{ x: number; y: number } | null>(null)

  const isWeek = view === "week"
  const selectedDay = selected === null ? undefined : WEEK[selected]
  const categories = selectedDay ?? DAILY_AVERAGE
  const headline = selectedDay ? total(selectedDay) : AVERAGE
  const data = isWeek
    ? WEEK.map((day, index) => ({
        ...day,
        label: DAYS[index]?.slice(0, 3) ?? "",
        index,
      }))
    : hourly(selected ?? 6)
  const apps = APPS.map((app) => ({
    ...app,
    minutes: categories[app.category] * app.share,
  }))
    .sort((a, b) => b.minutes - a.minutes)
    .slice(0, 5)
  const longest = Math.max(...apps.map((app) => app.minutes))
  const comparison =
    selected === null
      ? "8% less than last week"
      : `${Math.round(Math.abs(headline / AVERAGE - 1) * 100)}% ${headline > AVERAGE ? "above" : "below"} average`

  const select = (index: number) => {
    if (!isWeek) return
    setSelected((current) => (current === index ? null : index))
  }

  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-52 flex-1 flex-col gap-0.5"
          aria-live="polite"
        >
          <p className="text-sm font-semibold text-muted-foreground">
            {selected === null ? "Daily average" : DAYS[selected]}
          </p>
          <p className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatMinutes(headline)}
          </p>
          <p className="text-sm text-muted-foreground">{comparison}</p>
        </div>
        <ToggleGroup
          spacing={0}
          value={[view]}
          onValueChange={(value: string[]) => {
            const next = value[0] as "week" | "day" | undefined
            if (!next) return
            setView(next)
            if (next === "day" && selected === null) setSelected(6)
          }}
          aria-label="Period"
        >
          <ToggleGroupItem value="week" size="sm" className="px-5">
            Week
          </ToggleGroupItem>
          <ToggleGroupItem value="day" size="sm" className="px-5">
            Day
          </ToggleGroupItem>
        </ToggleGroup>
      </CardHeader>
      <CardContent className="flex flex-col gap-5">
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-64 w-full data-[view=week]:[&_.recharts-bar-rectangle]:cursor-pointer"
          data-view={view}
          onKeyDown={(event) => {
            if (
              (event.key === "Enter" || event.key === " ") &&
              highlighted !== null
            ) {
              event.preventDefault()
              select(highlighted)
            }
          }}
          onBlur={(event) => {
            if (!event.currentTarget.contains(event.relatedTarget)) {
              setHighlighted(null)
            }
          }}
        >
          <BarChart
            accessibilityLayer
            data={data}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="label"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              ticks={isWeek ? undefined : ["0", "6", "12", "18"]}
              tickFormatter={(value: string) =>
                isWeek ? value : `${value}:00`
              }
            />
            <YAxis
              orientation="right"
              tickLine={false}
              axisLine={false}
              tickMargin={6}
              width="auto"
              ticks={isWeek ? [0, 120, 240, 360] : undefined}
              tickCount={isWeek ? undefined : 4}
              tickFormatter={(value: number) =>
                isWeek ? `${value / 60}h` : `${value}m`
              }
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  labelFormatter={(_, payload) => {
                    const label = payload[0]?.payload.label
                    return isWeek
                      ? DAYS[DAYS.findIndex((day) => day.startsWith(label))]
                      : `${label}:00 – ${Number(label) + 1}:00`
                  }}
                  formatter={(value, name) => (
                    <div className="flex w-full items-center gap-2">
                      <span
                        className="size-2 shrink-0 rounded-xs bg-(--swatch)"
                        style={
                          {
                            "--swatch": `var(--color-${name})`,
                          } as React.CSSProperties
                        }
                      />
                      <span className="flex-1 text-muted-foreground">
                        {chartConfig[name as Category].label}
                      </span>
                      <span className="font-semibold tabular-nums">
                        {formatMinutes(Number(value))}
                      </span>
                    </div>
                  )}
                />
              }
            />
            {isWeek && (
              <ReferenceLine
                y={AVERAGE}
                stroke="var(--color-green-500)"
                strokeDasharray="3 3"
              />
            )}
            {CATEGORIES.map((category, position) => (
              <Bar
                key={category}
                dataKey={category}
                stackId="a"
                fill={`var(--color-${category})`}
                radius={position === CATEGORIES.length - 1 ? [5, 5, 0, 0] : 0}
                maxBarSize={isWeek ? 34 : 10}
                isAnimationActive={false}
                onClick={(_, index) => select(index)}
                onTouchStart={(_, __, event) => {
                  const touch = event.touches[0]
                  if (!touch) return
                  touchRef.current = { x: touch.clientX, y: touch.clientY }
                }}
                onTouchEnd={(_, index, event) => {
                  const start = touchRef.current
                  const touch = event.changedTouches[0]
                  touchRef.current = null
                  if (
                    !start ||
                    !touch ||
                    Math.hypot(
                      touch.clientX - start.x,
                      touch.clientY - start.y
                    ) > TAP_SLOP
                  )
                    return
                  event.preventDefault()
                  select(index)
                }}
              >
                {isWeek &&
                  data.map((item, index) => (
                    <Cell
                      key={String(item.label)}
                      fillOpacity={
                        selected === null || selected === index ? 1 : 0.3
                      }
                      className="transition-[fill-opacity] duration-200"
                    />
                  ))}
              </Bar>
            ))}
            <KeyboardPoint onChange={setHighlighted} />
          </BarChart>
        </ChartContainer>
        <dl className="grid grid-cols-3 gap-3">
          {CATEGORIES.map((category) => (
            <div key={category} className="flex min-w-0 flex-col gap-0.5">
              <dt className="flex min-w-0 items-center gap-1.5 text-sm text-muted-foreground">
                <span
                  className="size-2 shrink-0 rounded-full bg-(--swatch)"
                  style={
                    {
                      "--swatch": chartConfig[category].color,
                    } as React.CSSProperties
                  }
                />
                <span className="truncate">{chartConfig[category].label}</span>
              </dt>
              <dd className="text-base font-semibold tabular-nums">
                {formatMinutes(categories[category])}
              </dd>
            </div>
          ))}
        </dl>
        <div className="flex flex-col">
          <p className="mb-1 text-xs font-semibold text-muted-foreground uppercase">
            Most used
          </p>
          <ul>
            {apps.map((app) => (
              <li
                key={app.name}
                onPointerEnter={() => setHoveredApp(app.name)}
                onPointerLeave={() => setHoveredApp(null)}
                className="grid grid-cols-[6rem_1fr_4.5rem] items-center gap-3 border-t border-border py-2"
              >
                <span className="truncate text-base">{app.name}</span>
                <span className="h-1.5 overflow-hidden rounded-full bg-secondary">
                  <span
                    data-dimmed={
                      hoveredApp !== null && hoveredApp !== app.name
                        ? ""
                        : undefined
                    }
                    className="block h-full origin-left rounded-full rtl:origin-right bg-(--swatch) transition-[scale,opacity] duration-400 ease-[cubic-bezier(0.32,0.72,0,1)] data-dimmed:opacity-40"
                    style={
                      {
                        "--swatch": chartConfig[app.category].color,
                        scale: `${app.minutes / longest} 1`,
                      } as React.CSSProperties
                    }
                  />
                </span>
                <span className="text-end text-sm text-muted-foreground tabular-nums">
                  {formatMinutes(app.minutes)}
                </span>
              </li>
            ))}
          </ul>
        </div>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartInteractive } from "@/components/charts/bar-chart-interactive"
```

```tsx
<BarChartInteractive />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-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 {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Category = "social" | "productivity" | "entertainment"

type Period = "week" | "day"

const CATEGORIES: Category[] = ["social", "productivity", "entertainment"]

const DAYS = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
]

const USAGE: [social: number, productivity: number, entertainment: number][] = [
  [48, 95, 62],
  [55, 120, 40],
  [70, 88, 95],
  [42, 130, 35],
  [65, 100, 80],
  [110, 30, 140],
  [95, 25, 120],
]

const WEEK: Record<Category, number>[] = USAGE.map(
  ([social, productivity, entertainment]) => ({
    social,
    productivity,
    entertainment,
  })
)

const PROFILE = [
  1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4,
]

const APPS: { name: string; category: Category; share: number }[] = [
  { name: "Chat", category: "social", share: 0.55 },
  { name: "Messages", category: "social", share: 0.45 },
  { name: "Browser", category: "productivity", share: 0.45 },
  { name: "Mail", category: "productivity", share: 0.3 },
  { name: "Docs", category: "productivity", share: 0.25 },
  { name: "Video", category: "entertainment", share: 0.6 },
  { name: "Music", category: "entertainment", share: 0.4 },
]

const chartConfig = {
  social: { label: "Social", color: "chart-1" },
  productivity: { label: "Productivity", color: "cyan-500" },
  entertainment: { label: "Entertainment", color: "chart-4" },
} satisfies ChartConfig

const SWATCH: Record<Category, string> = {
  social: "bg-blue-500",
  productivity: "bg-cyan-500",
  entertainment: "bg-orange-500",
}

const total = (day: Record<Category, number>) =>
  CATEGORIES.reduce((sum, category) => sum + day[category], 0)

const AVERAGE = WEEK.reduce((sum, day) => sum + total(day), 0) / WEEK.length

const DAILY_AVERAGE = Object.fromEntries(
  CATEGORIES.map((category) => [
    category,
    WEEK.reduce((sum, day) => sum + day[category], 0) / WEEK.length,
  ])
) as Record<Category, number>

function formatMinutes(minutes: number) {
  const rounded = Math.round(minutes)
  const hours = Math.floor(rounded / 60)
  return hours ? `${hours}h ${rounded % 60}m` : `${rounded}m`
}

function noise(seed: number) {
  const state = (seed * 16807) % 2147483647
  return (state - 1) / 2147483646
}

function hourly(day: number) {
  const profileTotal = PROFILE.reduce((sum, value) => sum + value, 0)
  const categories = WEEK[day]
  if (!categories) return []
  return PROFILE.map((weight, hour) => {
    const share =
      (weight / profileTotal) * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
    return {
      label: String(hour),
      index: hour,
      social: Math.round(categories.social * share),
      productivity: Math.round(
        categories.productivity * share * (hour > 8 && hour < 18 ? 1.6 : 0.4)
      ),
      entertainment: Math.round(
        categories.entertainment * share * (hour > 18 ? 1.8 : 0.5)
      ),
    }
  })
}

export function BarChartInteractive() {
  const [view, setView] = React.useState<Period>("week")
  const [selected, setSelected] = React.useState<number | null>(null)

  const isWeek = view === "week"
  const selectedDay = selected === null ? undefined : WEEK[selected]
  const categories = selectedDay ?? DAILY_AVERAGE
  const headline = selectedDay ? total(selectedDay) : AVERAGE
  const data = isWeek
    ? WEEK.map((day, index) => ({
        ...day,
        label: DAYS[index]?.slice(0, 3) ?? "",
        index,
      }))
    : hourly(selected ?? 6)
  const apps = APPS.map((app) => ({
    ...app,
    minutes: categories[app.category] * app.share,
  }))
    .sort((a, b) => b.minutes - a.minutes)
    .slice(0, 5)
  const longest = Math.max(...apps.map((app) => app.minutes))
  const comparison =
    selected === null
      ? "8% less than last week"
      : `${Math.round(Math.abs(headline / AVERAGE - 1) * 100)}% ${headline > AVERAGE ? "above" : "below"} average`

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View
          className="min-w-52 grow gap-0.5"
          accessibilityLiveRegion="polite"
        >
          <Text className="text-sm font-semibold text-muted-foreground">
            {selected === null ? "Daily average" : DAYS[selected]}
          </Text>
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatMinutes(headline)}
          </Text>
          <Text className="text-sm text-muted-foreground">{comparison}</Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[view]}
          onValueChange={(value) => {
            const next = value[0] as Period | undefined
            if (!next) return
            setView(next)
            if (next === "day" && selected === null) setSelected(6)
          }}
          accessibilityLabel="Period"
        >
          <ToggleGroupItem value="week" size="sm" className="px-5">
            <Text>Week</Text>
          </ToggleGroupItem>
          <ToggleGroupItem value="day" size="sm" className="px-5">
            <Text>Day</Text>
          </ToggleGroupItem>
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-5">
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          className="h-64 w-full"
        >
          <BarChart
            key={view}
            data={data}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
            onActiveIndexChange={isWeek ? setSelected : undefined}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="label"
              tickMargin={8}
              interval={0}
              ticks={isWeek ? undefined : ["0", "6", "12", "18"]}
              tickFormatter={(value) => (isWeek ? `${value}` : `${value}:00`)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={isWeek ? [0, 120, 240, 360] : undefined}
              tickCount={isWeek ? undefined : 4}
              tickFormatter={(value) =>
                isWeek ? `${Number(value) / 60}h` : `${value}m`
              }
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  labelFormatter={(_, payload) => {
                    const label = String(payload[0]?.payload.label ?? "")
                    return isWeek
                      ? DAYS.find((day) => day.startsWith(label))
                      : `${label}:00 – ${Number(label) + 1}:00`
                  }}
                  formatter={(value, name) => (
                    <View className="w-full flex-row items-center gap-2">
                      <View
                        className={cn(
                          "size-2 shrink-0 rounded-xs",
                          SWATCH[name as Category]
                        )}
                      />
                      <Text className="grow text-muted-foreground">
                        {chartConfig[name as Category].label}
                      </Text>
                      <Text className="font-semibold tabular-nums">
                        {formatMinutes(Number(value))}
                      </Text>
                    </View>
                  )}
                />
              }
            />
            {isWeek ? (
              <ReferenceLine
                y={AVERAGE}
                stroke="green-500"
                strokeDasharray="3 3"
              />
            ) : null}
            {CATEGORIES.map((category, position) => (
              <Bar
                isAnimationActive={false}
                key={category}
                dataKey={category}
                stackId="a"
                fill={chartConfig[category].color}
                radius={position === CATEGORIES.length - 1 ? [5, 5, 0, 0] : 0}
                maxBarSize={isWeek ? 34 : 10}
              >
                {isWeek
                  ? data.map((item, index) => (
                      <Cell
                        key={item.label}
                        fillOpacity={
                          selected === null || selected === index ? 1 : 0.3
                        }
                      />
                    ))
                  : null}
              </Bar>
            ))}
          </BarChart>
        </ChartContainer>
        <View className="flex-row gap-3">
          {CATEGORIES.map((category) => (
            <View key={category} accessible className="min-w-0 flex-1 gap-0.5">
              <View className="min-w-0 flex-row items-center gap-1.5">
                <View
                  className={cn(
                    "size-2 shrink-0 rounded-full",
                    SWATCH[category]
                  )}
                />
                <Text
                  numberOfLines={1}
                  className="shrink text-sm text-muted-foreground"
                >
                  {chartConfig[category].label}
                </Text>
              </View>
              <Text className="text-base font-semibold tabular-nums">
                {formatMinutes(categories[category])}
              </Text>
            </View>
          ))}
        </View>
        <View>
          <Text className="mb-1 text-xs font-semibold text-muted-foreground uppercase">
            Most used
          </Text>
          {apps.map((app) => (
            <View
              key={app.name}
              accessible
              className="flex-row items-center gap-3 border-t border-border py-2"
            >
              <Text numberOfLines={1} className="w-24 text-base">
                {app.name}
              </Text>
              <View className="h-1.5 grow overflow-hidden rounded-full bg-secondary">
                <View
                  style={{ width: `${(app.minutes / longest) * 100}%` }}
                  className={cn("h-full rounded-full", SWATCH[app.category])}
                />
              </View>
              <Text className="w-18 text-right text-sm text-muted-foreground tabular-nums">
                {formatMinutes(app.minutes)}
              </Text>
            </View>
          ))}
        </View>
      </CardContent>
    </Card>
  )
}
```

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

private enum Category: String, CaseIterable {
  case social, productivity, entertainment
}

private enum Period: String, CaseIterable {
  case week, day
}

private let days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

private let usage: [[Double]] = [
  [48, 95, 62], [55, 120, 40], [70, 88, 95], [42, 130, 35], [65, 100, 80], [110, 30, 140], [95, 25, 120],
]

private let profile: [Double] = [1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4]

private let apps: [(name: String, category: Category, share: Double)] = [
  ("Chat", .social, 0.55),
  ("Messages", .social, 0.45),
  ("Browser", .productivity, 0.45),
  ("Mail", .productivity, 0.3),
  ("Docs", .productivity, 0.25),
  ("Video", .entertainment, 0.6),
  ("Music", .entertainment, 0.4),
]

private let chartConfig: ChartConfig = [
  "social": .init("Social", color: EsuissColor.chart1),
  "productivity": .init("Productivity", color: Palette.cyan500),
  "entertainment": .init("Entertainment", color: EsuissColor.chart4),
]

private func week(_ day: Int, _ category: Category) -> Double {
  usage[day][Category.allCases.firstIndex(of: category) ?? 0]
}

private func total(_ day: Int) -> Double {
  Category.allCases.reduce(0) { $0 + week(day, $1) }
}

private let averageTotal = days.indices.reduce(0) { $0 + total($1) } / Double(days.count)

private func dailyAverage(_ category: Category) -> Double {
  days.indices.reduce(0) { $0 + week($1, category) } / Double(days.count)
}

private func formatMinutes(_ minutes: Double) -> String {
  let rounded = Int(minutes.rounded())
  let hours = rounded / 60
  return hours > 0 ? "\(hours)h \(rounded % 60)m" : "\(rounded)m"
}

private func noise(_ seed: Int) -> Double {
  Double((seed * 16807) % 2147483647 - 1) / 2147483646
}

private func hourly(_ day: Int, _ hour: Int, _ category: Category) -> Double {
  let profileTotal = profile.reduce(0, +)
  let share = profile[hour] / profileTotal * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
  switch category {
  case .social: return (week(day, .social) * share).rounded()
  case .productivity: return (week(day, .productivity) * share * (hour > 8 && hour < 18 ? 1.6 : 0.4)).rounded()
  case .entertainment: return (week(day, .entertainment) * share * (hour > 18 ? 1.8 : 0.5)).rounded()
  }
}

public struct BarChartInteractive: View {
  @State private var view: Period = .week
  @State private var selected: Int?
  @State private var hour: Int?
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init() {}

  private var isWeek: Bool { view == .week }

  private var labels: [String] {
    isWeek ? days.map { String($0.prefix(3)) } : profile.indices.map { "\($0)" }
  }

  private func value(_ index: Int, _ category: Category) -> Double {
    isWeek ? week(index, category) : hourly(selected ?? 6, index, category)
  }

  private var viewBinding: Binding<Period?> {
    Binding(get: { view }, set: { next in
      guard let next else { return }
      view = next
      hour = nil
      if next == .day && selected == nil { selected = 6 }
    })
  }

  private var selection: Binding<Int?> {
    isWeek ? $selected : $hour
  }

  public var body: some View {
    let categories: (Category) -> Double = { category in
      selected.map { week($0, category) } ?? dailyAverage(category)
    }
    let headline = selected.map(total) ?? averageTotal
    let ranked = apps.map { (app: $0, minutes: categories($0.category) * $0.share) }
      .sorted { $0.minutes > $1.minutes }
      .prefix(5)
    let longest = ranked.map(\.minutes).max() ?? 1
    let comparison = selected == nil
      ? "8% less than last week"
      : "\(Int((abs(headline / averageTotal - 1) * 100).rounded()))% \(headline > averageTotal ? "above" : "below") average"
    Card(.filled, size: .sm) {
      VStack(alignment: .leading, spacing: 16) {
        VStack(alignment: .leading, spacing: 2) {
          Text(LocalizedStringKey(selected.map { days[$0] } ?? "Daily average"))
            .textStyle(.sm, weight: .semibold)
            .foregroundStyle(EsuissColor.mutedForeground)
          Text(verbatim: formatMinutes(headline))
            .textStyle(.xl3, weight: .semibold)
            .monospacedDigit()
          Text(LocalizedStringKey(comparison))
            .textStyle(.sm)
            .foregroundStyle(EsuissColor.mutedForeground)
        }
        .accessibilityElement(children: .combine)
        ToggleGroup(selection: viewBinding, size: .sm, spacing: 0) {
          ToggleGroupItem(value: Period.week) { Text("Week").padding(.horizontal, 8) }
          ToggleGroupItem(value: Period.day) { Text("Day").padding(.horizontal, 8) }
        }
        .accessibilityLabel("Period")
      }
      .padding(.horizontal, 16)
      CardContent {
        VStack(alignment: .leading, spacing: 20) {
          chart
          LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12, alignment: .leading), count: 3), spacing: 12) {
            ForEach(Category.allCases, id: \.self) { category in
              VStack(alignment: .leading, spacing: 2) {
                HStack(spacing: 6) {
                  Circle()
                    .fill(chartConfig.color(category.rawValue))
                    .frame(width: 8, height: 8)
                  Text(LocalizedStringKey(chartConfig.label(category.rawValue)))
                    .textStyle(.sm)
                    .foregroundStyle(EsuissColor.mutedForeground)
                    .lineLimit(1)
                }
                Text(verbatim: formatMinutes(categories(category)))
                  .textStyle(.base, weight: .semibold)
                  .monospacedDigit()
              }
              .accessibilityElement(children: .combine)
            }
          }
          VStack(alignment: .leading, spacing: 0) {
            Text("MOST USED")
              .textStyle(.xs, weight: .semibold)
              .foregroundStyle(EsuissColor.mutedForeground)
              .padding(.bottom, 4)
            ForEach(Array(ranked), id: \.app.name) { entry in
              HStack(spacing: 12) {
                Text(LocalizedStringKey(entry.app.name))
                  .textStyle(.base)
                  .lineLimit(1)
                  .frame(width: 96, alignment: .leading)
                GeometryReader { geometry in
                  Capsule()
                    .fill(EsuissColor.secondary)
                    .overlay(alignment: .leading) {
                      Capsule()
                        .fill(chartConfig.color(entry.app.category.rawValue))
                        .frame(width: geometry.size.width * entry.minutes / longest)
                    }
                }
                .frame(height: 6)
                Text(verbatim: formatMinutes(entry.minutes))
                  .textStyle(.sm)
                  .foregroundStyle(EsuissColor.mutedForeground)
                  .monospacedDigit()
                  .frame(width: 72, alignment: .trailing)
              }
              .padding(.vertical, 8)
              .overlay(alignment: .top) {
                EsuissColor.border.frame(height: 1)
              }
              .accessibilityElement(children: .combine)
            }
          }
          .animation(reduceMotion ? nil : .timingCurve(0.32, 0.72, 0, 1, duration: 0.4), value: selected)
        }
      }
    }
  }

  private var chart: some View {
    let labels = labels
    return ChartContainer(config: chartConfig) {
      Chart {
        ForEach(labels.indices, id: \.self) { index in
          let dimmed = isWeek && selected != nil && selected != index
          ForEach(Category.allCases, id: \.self) { category in
            let start = Category.allCases.prefix { $0 != category }.reduce(0) { $0 + value(index, $1) }
            BarMark(
              x: .value("Time", labels[index]),
              yStart: .value("Start", start),
              yEnd: .value("End", start + value(index, category)),
              width: .fixed(isWeek ? 34 : 10)
            )
            .clipShape(UnevenRoundedRectangle(
              topLeadingRadius: category == .entertainment ? 5 : 0,
              topTrailingRadius: category == .entertainment ? 5 : 0,
              style: .continuous
            ))
            .foregroundStyle(chartConfig.color(category.rawValue).opacity(dimmed ? 0.3 : 1))
          }
        }
        if isWeek {
          RuleMark(y: .value("Average", averageTotal))
            .lineStyle(StrokeStyle(lineWidth: 1, dash: [3, 3]))
            .foregroundStyle(Palette.green500)
        }
      }
      .chartXAxis {
        ChartAxis.x(values: isWeek ? labels : ["0", "6", "12", "18"]) { isWeek ? $0 : "\($0):00" }
      }
      .chartYAxis {
        if isWeek {
          ChartAxis.y(values: [0.0, 120, 240, 360]) { "\(Int($0 / 60))h" }
        } else {
          ChartAxis.y(count: 4) { "\(Int($0))m" }
        }
      }
      .animation(reduceMotion ? nil : .easeOut(duration: 0.2), value: selected)
      .chartTooltip(
        x: labels,
        labels: isWeek ? days : labels.map { "\($0):00 – \((Int($0) ?? 0) + 1):00" },
        selection: selection,
        cursor: false,
        accessibilityLabel: "Screen time",
        items: { index in Category.allCases.map { ChartTooltipItem($0.rawValue, value: value(index, $0)) } }
      ) { payload in
        ChartTooltipContent(payload) { item in
          RoundedRectangle(cornerRadius: 2, style: .continuous)
            .fill(chartConfig.color(item.key))
            .frame(width: 8, height: 8)
          Text(LocalizedStringKey(chartConfig.label(item.key)))
            .foregroundStyle(EsuissColor.mutedForeground)
            .frame(maxWidth: .infinity, alignment: .leading)
          Text(verbatim: formatMinutes(item.value))
            .scaledFont(TextStyle.xs, weight: .semibold)
            .monospacedDigit()
        }
      }
      .id(view)
    }
    .frame(height: 256)
  }
}
```

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

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.LiveRegionMode
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
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.BarChart
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.ChartCell
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
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.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography
import kotlin.math.abs
import kotlin.math.roundToInt

private val categories = listOf("social", "productivity", "entertainment")

private val days = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")

private val week: List<Map<String, Double>> = listOf(
    listOf(48, 95, 62),
    listOf(55, 120, 40),
    listOf(70, 88, 95),
    listOf(42, 130, 35),
    listOf(65, 100, 80),
    listOf(110, 30, 140),
    listOf(95, 25, 120),
).map { usage -> categories.zip(usage.map { it.toDouble() }).toMap() }

private val profile = listOf(1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4)

private class AppUsage(val name: String, val category: String, val share: Double)

private val apps = listOf(
    AppUsage("Chat", "social", 0.55),
    AppUsage("Messages", "social", 0.45),
    AppUsage("Browser", "productivity", 0.45),
    AppUsage("Mail", "productivity", 0.3),
    AppUsage("Docs", "productivity", 0.25),
    AppUsage("Video", "entertainment", 0.6),
    AppUsage("Music", "entertainment", 0.4),
)

private val chartConfig = ChartConfig(
    "social" to ChartConfigItem("Social") { chart1 },
    "productivity" to ChartConfigItem("Productivity") { Palette.cyan500 },
    "entertainment" to ChartConfigItem("Entertainment") { chart4 },
)

private class UsageRow(val label: String, val values: Map<String, Double>)

private fun total(day: Map<String, Double>) = categories.sumOf { day.getValue(it) }

private val average = week.sumOf { total(it) } / week.size

private val dailyAverage = categories.associateWith { category -> week.sumOf { it.getValue(category) } / week.size }

private fun formatMinutes(minutes: Double): String {
    val rounded = minutes.roundToInt()
    val hours = rounded / 60
    return if (hours > 0) "${hours}h ${rounded % 60}m" else "${rounded}m"
}

private fun noise(seed: Int): Double {
    val state = seed.toLong() * 16807 % 2147483647
    return (state - 1) / 2147483646.0
}

private fun hourly(day: Int): List<UsageRow> {
    val profileTotal = profile.sum().toDouble()
    val values = week[day]
    return profile.mapIndexed { hour, weight ->
        val share = weight / profileTotal * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
        UsageRow(
            hour.toString(),
            mapOf(
                "social" to (values.getValue("social") * share).roundToInt().toDouble(),
                "productivity" to (values.getValue("productivity") * share * if (hour in 9..17) 1.6 else 0.4).roundToInt().toDouble(),
                "entertainment" to (values.getValue("entertainment") * share * if (hour > 18) 1.8 else 0.5).roundToInt().toDouble(),
            ),
        )
    }
}

@Composable
fun BarChartInteractive(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    var view by remember { mutableStateOf("week") }
    var selected by remember { mutableStateOf<Int?>(null) }
    var hour by remember { mutableStateOf<Int?>(null) }
    val isWeek = view == "week"
    val selectedDay = selected?.let { week[it] }
    val values = selectedDay ?: dailyAverage
    val headline = selectedDay?.let(::total) ?: average
    val data = if (isWeek) {
        week.mapIndexed { index, day -> UsageRow(days[index].take(3), day) }
    } else {
        hourly(selected ?: 6)
    }
    val usage = apps.map { it to values.getValue(it.category) * it.share }.sortedByDescending { it.second }.take(5)
    val longest = usage.maxOf { it.second }
    val comparison = if (selected == null) {
        "8% less than last week"
    } else {
        "${(abs(headline / average - 1) * 100).roundToInt()}% ${if (headline > average) "above" else "below"} average"
    }
    val swatch = { key: String -> chartConfig[key]?.color?.invoke(colors) ?: colors.mutedForeground }
    val value = Typography.base.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum")
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
                Column(
                    Modifier.semantics { liveRegion = LiveRegionMode.Polite },
                    verticalArrangement = Arrangement.spacedBy(2.dp),
                ) {
                    BasicText(
                        selected?.let { days[it] } ?: "Daily average",
                        style = Typography.sm.copy(color = colors.mutedForeground, fontWeight = FontWeight.SemiBold),
                    )
                    BasicText(
                        formatMinutes(headline),
                        style = Typography.xl3.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                    )
                    BasicText(comparison, style = Typography.sm.copy(color = colors.mutedForeground))
                }
                ToggleGroup(
                    value = view,
                    onValueChange = { next ->
                        if (next != null) {
                            view = next
                            hour = null
                            if (next == "day" && selected == null) selected = 6
                        }
                    },
                    size = ToggleSize.Sm,
                    spacing = 0,
                ) {
                    ToggleGroupItem("Week", "week", Modifier.padding(horizontal = 8.dp))
                    ToggleGroupItem("Day", "day", Modifier.padding(horizontal = 8.dp))
                }
            }
        }
        CardContent {
            Column(verticalArrangement = Arrangement.spacedBy(20.dp)) {
                ChartContainer(
                    chartConfig,
                    Modifier
                        .fillMaxWidth()
                        .height(256.dp),
                ) {
                    BarChart(
                        data,
                        margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 12.dp),
                        accessibilityLabel = if (isWeek) "Screen time this week" else "Screen time by hour",
                        selectedIndex = if (isWeek) selected else hour,
                        onSelectedIndexChange = { index -> if (isWeek) selected = index else hour = index },
                    ) {
                        CartesianGrid(strokeDasharray = listOf(2f, 4f))
                        if (isWeek) {
                            XAxis(label = { it.label }, tickMargin = 8.dp, interval = 0)
                            YAxis(
                                orientation = ChartAxisOrientation.Right,
                                tickMargin = 6.dp,
                                ticks = listOf(0.0, 120.0, 240.0, 360.0),
                                tickFormatter = { "${(it / 60).toInt()}h" },
                            )
                            ReferenceLine(average, stroke = Palette.green500, strokeDasharray = listOf(3f, 3f))
                        } else {
                            XAxis(label = { it.label }, tickMargin = 8.dp, interval = 0, ticks = listOf(0, 6, 12, 18), tickFormatter = { "$it:00" })
                            YAxis(orientation = ChartAxisOrientation.Right, tickMargin = 6.dp, tickCount = 4, tickFormatter = { "${it.toInt()}m" })
                        }
                        ChartTooltip(cursor = null) {
                            ChartTooltipContent(
                                labelFormatter = { label, _ ->
                                    BasicText(
                                        if (isWeek) days.first { it.startsWith(label) } else "$label:00 – ${label.toInt() + 1}:00",
                                        style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold),
                                    )
                                },
                                formatter = { item ->
                                    Row(
                                        Modifier.fillMaxWidth(),
                                        horizontalArrangement = Arrangement.spacedBy(8.dp),
                                        verticalAlignment = Alignment.CenterVertically,
                                    ) {
                                        Box(
                                            Modifier
                                                .size(8.dp)
                                                .background(item.color, RoundedCornerShape(Radius.xs)),
                                        )
                                        BasicText(
                                            chartConfig[item.key]?.label ?: item.key,
                                            Modifier.weight(1f),
                                            style = Typography.xs.copy(color = colors.mutedForeground),
                                        )
                                        BasicText(
                                            formatMinutes(item.value),
                                            style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                                        )
                                    }
                                },
                            )
                        }
                        categories.forEachIndexed { position, category ->
                            Bar(
                                category,
                                value = { it.values.getValue(category) },
                                stackId = "a",
                                radius = if (position == categories.size - 1) ChartRadius(5.dp, 5.dp, 0.dp, 0.dp) else ChartRadius(0.dp),
                                maxBarSize = if (isWeek) 34.dp else 10.dp,
                                cells = if (isWeek) {
                                    { index -> ChartCell(alpha = if (selected == null || selected == index) 1f else 0.3f) }
                                } else {
                                    null
                                },
                                isAnimationActive = false,
                            )
                        }
                    }
                }
                Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
                    for (category in categories) {
                        Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
                            Row(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically) {
                                Box(
                                    Modifier
                                        .size(8.dp)
                                        .background(swatch(category), CircleShape),
                                )
                                BasicText(
                                    chartConfig[category]?.label ?: category,
                                    style = Typography.sm.copy(color = colors.mutedForeground),
                                    maxLines = 1,
                                    overflow = TextOverflow.Ellipsis,
                                )
                            }
                            BasicText(formatMinutes(values.getValue(category)), style = value)
                        }
                    }
                }
                Column {
                    BasicText(
                        "MOST USED",
                        Modifier.padding(bottom = 4.dp),
                        style = Typography.xs.copy(color = colors.mutedForeground, fontWeight = FontWeight.SemiBold),
                    )
                    for ((app, minutes) in usage) {
                        Separator()
                        val fraction by animateFloatAsState((minutes / longest).toFloat(), label = "fraction")
                        Row(
                            Modifier
                                .fillMaxWidth()
                                .padding(vertical = 8.dp),
                            horizontalArrangement = Arrangement.spacedBy(12.dp),
                            verticalAlignment = Alignment.CenterVertically,
                        ) {
                            BasicText(
                                app.name,
                                Modifier.width(96.dp),
                                style = Typography.base.copy(color = colors.foreground),
                                maxLines = 1,
                                overflow = TextOverflow.Ellipsis,
                            )
                            Box(
                                Modifier
                                    .weight(1f)
                                    .height(6.dp)
                                    .background(colors.secondary, CircleShape),
                            ) {
                                Box(
                                    Modifier
                                        .fillMaxWidth(fraction)
                                        .fillMaxHeight()
                                        .background(swatch(app.category), CircleShape),
                                )
                            }
                            BasicText(
                                formatMinutes(minutes),
                                Modifier.width(72.dp),
                                style = Typography.sm.copy(color = colors.mutedForeground, fontFeatureSettings = "tnum", textAlign = TextAlign.End),
                            )
                        }
                    }
                }
            }
        }
    }
}
```

**React Native**

Bars stack social, productivity and entertainment time. A `ToggleGroup` switches between a weekly view and an hourly view of one day. In the week view, touching a bar selects that day through `onActiveIndexChange`, dims the other days and updates the headline, comparison text, category totals and the most used apps list below. A dashed line marks the weekly average. The bars set `isAnimationActive={false}`, so they draw without the enter animation and switch views instantly.

Replace `USAGE` with daily minutes per category and `APPS` with your apps and their share of each category. The hourly view is generated from `PROFILE`, so swap `hourly()` for real data. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-interactive
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-interactive --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-interactive.tsx`:

- `uniwind/components/charts/bar-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/bar-chart-interactive.tsx`:

```tsx title="nativewind/components/charts/bar-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 {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Category = "social" | "productivity" | "entertainment"

type Period = "week" | "day"

const CATEGORIES: Category[] = ["social", "productivity", "entertainment"]

const DAYS = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
]

const USAGE: [social: number, productivity: number, entertainment: number][] = [
  [48, 95, 62],
  [55, 120, 40],
  [70, 88, 95],
  [42, 130, 35],
  [65, 100, 80],
  [110, 30, 140],
  [95, 25, 120],
]

const WEEK: Record<Category, number>[] = USAGE.map(
  ([social, productivity, entertainment]) => ({
    social,
    productivity,
    entertainment,
  })
)

const PROFILE = [
  1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4,
]

const APPS: { name: string; category: Category; share: number }[] = [
  { name: "Chat", category: "social", share: 0.55 },
  { name: "Messages", category: "social", share: 0.45 },
  { name: "Browser", category: "productivity", share: 0.45 },
  { name: "Mail", category: "productivity", share: 0.3 },
  { name: "Docs", category: "productivity", share: 0.25 },
  { name: "Video", category: "entertainment", share: 0.6 },
  { name: "Music", category: "entertainment", share: 0.4 },
]

const chartConfig = {
  social: { label: "Social", color: "chart-1" },
  productivity: { label: "Productivity", color: "cyan-500" },
  entertainment: { label: "Entertainment", color: "chart-4" },
} satisfies ChartConfig

const SWATCH: Record<Category, string> = {
  social: "bg-blue-500",
  productivity: "bg-cyan-500",
  entertainment: "bg-orange-500",
}

const total = (day: Record<Category, number>) =>
  CATEGORIES.reduce((sum, category) => sum + day[category], 0)

const AVERAGE = WEEK.reduce((sum, day) => sum + total(day), 0) / WEEK.length

const DAILY_AVERAGE = Object.fromEntries(
  CATEGORIES.map((category) => [
    category,
    WEEK.reduce((sum, day) => sum + day[category], 0) / WEEK.length,
  ])
) as Record<Category, number>

function formatMinutes(minutes: number) {
  const rounded = Math.round(minutes)
  const hours = Math.floor(rounded / 60)
  return hours ? `${hours}h ${rounded % 60}m` : `${rounded}m`
}

function noise(seed: number) {
  const state = (seed * 16807) % 2147483647
  return (state - 1) / 2147483646
}

function hourly(day: number) {
  const profileTotal = PROFILE.reduce((sum, value) => sum + value, 0)
  const categories = WEEK[day]
  if (!categories) return []
  return PROFILE.map((weight, hour) => {
    const share =
      (weight / profileTotal) * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
    return {
      label: String(hour),
      index: hour,
      social: Math.round(categories.social * share),
      productivity: Math.round(
        categories.productivity * share * (hour > 8 && hour < 18 ? 1.6 : 0.4)
      ),
      entertainment: Math.round(
        categories.entertainment * share * (hour > 18 ? 1.8 : 0.5)
      ),
    }
  })
}

export function BarChartInteractive() {
  const [view, setView] = React.useState<Period>("week")
  const [selected, setSelected] = React.useState<number | null>(null)

  const isWeek = view === "week"
  const selectedDay = selected === null ? undefined : WEEK[selected]
  const categories = selectedDay ?? DAILY_AVERAGE
  const headline = selectedDay ? total(selectedDay) : AVERAGE
  const data = isWeek
    ? WEEK.map((day, index) => ({
        ...day,
        label: DAYS[index]?.slice(0, 3) ?? "",
        index,
      }))
    : hourly(selected ?? 6)
  const apps = APPS.map((app) => ({
    ...app,
    minutes: categories[app.category] * app.share,
  }))
    .sort((a, b) => b.minutes - a.minutes)
    .slice(0, 5)
  const longest = Math.max(...apps.map((app) => app.minutes))
  const comparison =
    selected === null
      ? "8% less than last week"
      : `${Math.round(Math.abs(headline / AVERAGE - 1) * 100)}% ${headline > AVERAGE ? "above" : "below"} average`

  return (
    <Card variant="filled" size="sm">
      <CardHeader className="flex-row flex-wrap items-start justify-between gap-4">
        <View
          className="min-w-52 grow gap-0.5"
          accessibilityLiveRegion="polite"
        >
          <Text className="text-sm font-semibold text-muted-foreground">
            {selected === null ? "Daily average" : DAYS[selected]}
          </Text>
          <Text className="text-3xl font-semibold tracking-tight tabular-nums">
            {formatMinutes(headline)}
          </Text>
          <Text className="text-sm text-muted-foreground">{comparison}</Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[view]}
          onValueChange={(value) => {
            const next = value[0] as Period | undefined
            if (!next) return
            setView(next)
            if (next === "day" && selected === null) setSelected(6)
          }}
          accessibilityLabel="Period"
        >
          <ToggleGroupItem value="week" size="sm" className="px-5">
            <Text>Week</Text>
          </ToggleGroupItem>
          <ToggleGroupItem value="day" size="sm" className="px-5">
            <Text>Day</Text>
          </ToggleGroupItem>
        </ToggleGroup>
      </CardHeader>
      <CardContent className="gap-5">
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          className="h-64 w-full"
        >
          <BarChart
            key={view}
            data={data}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
            onActiveIndexChange={isWeek ? setSelected : undefined}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="label"
              tickMargin={8}
              interval={0}
              ticks={isWeek ? undefined : ["0", "6", "12", "18"]}
              tickFormatter={(value) => (isWeek ? `${value}` : `${value}:00`)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={isWeek ? [0, 120, 240, 360] : undefined}
              tickCount={isWeek ? undefined : 4}
              tickFormatter={(value) =>
                isWeek ? `${Number(value) / 60}h` : `${value}m`
              }
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  labelFormatter={(_, payload) => {
                    const label = String(payload[0]?.payload.label ?? "")
                    return isWeek
                      ? DAYS.find((day) => day.startsWith(label))
                      : `${label}:00 – ${Number(label) + 1}:00`
                  }}
                  formatter={(value, name) => (
                    <View className="w-full flex-row items-center gap-2">
                      <View
                        className={cn(
                          "size-2 shrink-0 rounded-xs",
                          SWATCH[name as Category]
                        )}
                      />
                      <Text className="grow text-muted-foreground">
                        {chartConfig[name as Category].label}
                      </Text>
                      <Text className="font-semibold tabular-nums">
                        {formatMinutes(Number(value))}
                      </Text>
                    </View>
                  )}
                />
              }
            />
            {isWeek ? (
              <ReferenceLine
                y={AVERAGE}
                stroke="green-500"
                strokeDasharray="3 3"
              />
            ) : null}
            {CATEGORIES.map((category, position) => (
              <Bar
                isAnimationActive={false}
                key={category}
                dataKey={category}
                stackId="a"
                fill={chartConfig[category].color}
                radius={position === CATEGORIES.length - 1 ? [5, 5, 0, 0] : 0}
                maxBarSize={isWeek ? 34 : 10}
              >
                {isWeek
                  ? data.map((item, index) => (
                      <Cell
                        key={item.label}
                        fillOpacity={
                          selected === null || selected === index ? 1 : 0.3
                        }
                      />
                    ))
                  : null}
              </Bar>
            ))}
          </BarChart>
        </ChartContainer>
        <View className="flex-row gap-3">
          {CATEGORIES.map((category) => (
            <View key={category} accessible className="min-w-0 flex-1 gap-0.5">
              <View className="min-w-0 flex-row items-center gap-1.5">
                <View
                  className={cn(
                    "size-2 shrink-0 rounded-full",
                    SWATCH[category]
                  )}
                />
                <Text
                  numberOfLines={1}
                  className="shrink text-sm text-muted-foreground"
                >
                  {chartConfig[category].label}
                </Text>
              </View>
              <Text className="text-base font-semibold tabular-nums">
                {formatMinutes(categories[category])}
              </Text>
            </View>
          ))}
        </View>
        <View>
          <Text className="mb-1 text-xs font-semibold text-muted-foreground uppercase">
            Most used
          </Text>
          {apps.map((app) => (
            <View
              key={app.name}
              accessible
              className="flex-row items-center gap-3 border-t border-border py-2"
            >
              <Text numberOfLines={1} className="w-24 text-base">
                {app.name}
              </Text>
              <View className="h-1.5 grow overflow-hidden rounded-full bg-secondary">
                <View
                  style={{ width: `${(app.minutes / longest) * 100}%` }}
                  className={cn("h-full rounded-full", SWATCH[app.category])}
                />
              </View>
              <Text className="w-[4.5rem] text-right text-sm text-muted-foreground tabular-nums">
                {formatMinutes(app.minutes)}
              </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/bar-chart-interactive.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-interactive.tsx"
import * as React from "react"
import { StyleSheet, View } from "react-native"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import {
  fontSize,
  palette,
  type ThemeColors,
  useTheme,
} from "@/components/ui/theme"

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

type Tone = keyof ThemeColors | keyof typeof palette

function tone(colors: ThemeColors, key: Tone) {
  return { ...colors, ...palette }[key]
}

type Category = "social" | "productivity" | "entertainment"

type Period = "week" | "day"

const CATEGORIES: Category[] = ["social", "productivity", "entertainment"]

const DAYS = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
]

const USAGE: [social: number, productivity: number, entertainment: number][] = [
  [48, 95, 62],
  [55, 120, 40],
  [70, 88, 95],
  [42, 130, 35],
  [65, 100, 80],
  [110, 30, 140],
  [95, 25, 120],
]

const WEEK: Record<Category, number>[] = USAGE.map(
  ([social, productivity, entertainment]) => ({
    social,
    productivity,
    entertainment,
  })
)

const PROFILE = [
  1, 0, 0, 0, 0, 0, 1, 4, 6, 5, 4, 5, 7, 6, 5, 4, 5, 6, 7, 9, 10, 11, 8, 4,
]

const APPS: { name: string; category: Category; share: number }[] = [
  { name: "Chat", category: "social", share: 0.55 },
  { name: "Messages", category: "social", share: 0.45 },
  { name: "Browser", category: "productivity", share: 0.45 },
  { name: "Mail", category: "productivity", share: 0.3 },
  { name: "Docs", category: "productivity", share: 0.25 },
  { name: "Video", category: "entertainment", share: 0.6 },
  { name: "Music", category: "entertainment", share: 0.4 },
]

const chartConfig = {
  social: { label: "Social", color: "chart-1" },
  productivity: { label: "Productivity", color: "cyan-500" },
  entertainment: { label: "Entertainment", color: "chart-4" },
} satisfies ChartConfig

const SWATCH: Record<Category, Tone> = {
  social: "chart1",
  productivity: "cyan500",
  entertainment: "chart4",
}

const styles = StyleSheet.create({
  header: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "flex-start",
    justifyContent: "space-between",
    gap: 16,
  },
  heading: { minWidth: 208, flexGrow: 1, gap: 2 },
  eyebrow: { ...fontSize.sm, fontWeight: "600" },
  value: {
    ...fontSize["3xl"],
    fontWeight: "600",
    letterSpacing: -0.75,
    fontVariant: ["tabular-nums"],
  },
  caption: { ...fontSize.sm },
  period: { paddingHorizontal: 20 },
  content: { gap: 20 },
  chart: { height: 256 },
  row: { width: "100%", flexDirection: "row", alignItems: "center", gap: 8 },
  square: { width: 8, height: 8, flexShrink: 0, borderRadius: 2 },
  grow: { flexGrow: 1 },
  strong: { fontWeight: "600", fontVariant: ["tabular-nums"] },
  stats: { flexDirection: "row", gap: 12 },
  stat: { minWidth: 0, flex: 1, gap: 2 },
  statLabel: {
    minWidth: 0,
    flexDirection: "row",
    alignItems: "center",
    gap: 6,
  },
  dot: { width: 8, height: 8, flexShrink: 0, borderRadius: 9999 },
  shrink: { flexShrink: 1, ...fontSize.sm },
  statValue: {
    ...fontSize.base,
    fontWeight: "600",
    fontVariant: ["tabular-nums"],
  },
  section: {
    marginBottom: 4,
    ...fontSize.xs,
    fontWeight: "600",
    textTransform: "uppercase",
  },
  app: {
    flexDirection: "row",
    alignItems: "center",
    gap: 12,
    borderTopWidth: StyleSheet.hairlineWidth,
    paddingVertical: 8,
  },
  appName: { width: 96, ...fontSize.base },
  track: {
    height: 6,
    flexGrow: 1,
    overflow: "hidden",
    borderRadius: 9999,
  },
  fill: { height: "100%", borderRadius: 9999 },
  time: {
    width: 72,
    textAlign: "right",
    ...fontSize.sm,
    fontVariant: ["tabular-nums"],
  },
})

const total = (day: Record<Category, number>) =>
  CATEGORIES.reduce((sum, category) => sum + day[category], 0)

const AVERAGE = WEEK.reduce((sum, day) => sum + total(day), 0) / WEEK.length

const DAILY_AVERAGE = Object.fromEntries(
  CATEGORIES.map((category) => [
    category,
    WEEK.reduce((sum, day) => sum + day[category], 0) / WEEK.length,
  ])
) as Record<Category, number>

function formatMinutes(minutes: number) {
  const rounded = Math.round(minutes)
  const hours = Math.floor(rounded / 60)
  return hours ? `${hours}h ${rounded % 60}m` : `${rounded}m`
}

function noise(seed: number) {
  const state = (seed * 16807) % 2147483647
  return (state - 1) / 2147483646
}

function hourly(day: number) {
  const profileTotal = PROFILE.reduce((sum, value) => sum + value, 0)
  const categories = WEEK[day]
  if (!categories) return []
  return PROFILE.map((weight, hour) => {
    const share =
      (weight / profileTotal) * (0.75 + noise(hour + 7 * (day + 1)) * 0.5)
    return {
      label: String(hour),
      index: hour,
      social: Math.round(categories.social * share),
      productivity: Math.round(
        categories.productivity * share * (hour > 8 && hour < 18 ? 1.6 : 0.4)
      ),
      entertainment: Math.round(
        categories.entertainment * share * (hour > 18 ? 1.8 : 0.5)
      ),
    }
  })
}

export function BarChartInteractive() {
  const { colors } = useTheme()
  const [view, setView] = React.useState<Period>("week")
  const [selected, setSelected] = React.useState<number | null>(null)

  const isWeek = view === "week"
  const selectedDay = selected === null ? undefined : WEEK[selected]
  const categories = selectedDay ?? DAILY_AVERAGE
  const headline = selectedDay ? total(selectedDay) : AVERAGE
  const data = isWeek
    ? WEEK.map((day, index) => ({
        ...day,
        label: DAYS[index]?.slice(0, 3) ?? "",
        index,
      }))
    : hourly(selected ?? 6)
  const apps = APPS.map((app) => ({
    ...app,
    minutes: categories[app.category] * app.share,
  }))
    .sort((a, b) => b.minutes - a.minutes)
    .slice(0, 5)
  const longest = Math.max(...apps.map((app) => app.minutes))
  const comparison =
    selected === null
      ? "8% less than last week"
      : `${Math.round(Math.abs(headline / AVERAGE - 1) * 100)}% ${headline > AVERAGE ? "above" : "below"} average`

  return (
    <Card variant="filled" size="sm">
      <CardHeader style={styles.header}>
        <View style={styles.heading} accessibilityLiveRegion="polite">
          <Text style={[styles.eyebrow, { color: colors.mutedForeground }]}>
            {selected === null ? "Daily average" : DAYS[selected]}
          </Text>
          <Text style={styles.value}>{formatMinutes(headline)}</Text>
          <Text style={[styles.caption, { color: colors.mutedForeground }]}>
            {comparison}
          </Text>
        </View>
        <ToggleGroup
          spacing={0}
          value={[view]}
          onValueChange={(value) => {
            const next = value[0] as Period | undefined
            if (!next) return
            setView(next)
            if (next === "day" && selected === null) setSelected(6)
          }}
          accessibilityLabel="Period"
        >
          <ToggleGroupItem value="week" size="sm" style={styles.period}>
            <Text>Week</Text>
          </ToggleGroupItem>
          <ToggleGroupItem value="day" size="sm" style={styles.period}>
            <Text>Day</Text>
          </ToggleGroupItem>
        </ToggleGroup>
      </CardHeader>
      <CardContent style={styles.content}>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Screen time"
          style={styles.chart}
        >
          <BarChart
            key={view}
            data={data}
            margin={{ top: 10, right: 4, left: 12, bottom: 0 }}
            onActiveIndexChange={isWeek ? setSelected : undefined}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="label"
              tickMargin={8}
              interval={0}
              ticks={isWeek ? undefined : ["0", "6", "12", "18"]}
              tickFormatter={(value) => (isWeek ? `${value}` : `${value}:00`)}
            />
            <YAxis
              orientation="right"
              tickMargin={6}
              width="auto"
              ticks={isWeek ? [0, 120, 240, 360] : undefined}
              tickCount={isWeek ? undefined : 4}
              tickFormatter={(value) =>
                isWeek ? `${Number(value) / 60}h` : `${value}m`
              }
            />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  labelFormatter={(_, payload) => {
                    const label = String(payload[0]?.payload.label ?? "")
                    return isWeek
                      ? DAYS.find((day) => day.startsWith(label))
                      : `${label}:00 – ${Number(label) + 1}:00`
                  }}
                  formatter={(value, name) => (
                    <View style={styles.row}>
                      <View
                        style={[
                          styles.square,
                          {
                            backgroundColor: tone(
                              colors,
                              SWATCH[name as Category]
                            ),
                          },
                        ]}
                      />
                      <Text
                        style={[styles.grow, { color: colors.mutedForeground }]}
                      >
                        {chartConfig[name as Category].label}
                      </Text>
                      <Text style={styles.strong}>
                        {formatMinutes(Number(value))}
                      </Text>
                    </View>
                  )}
                />
              }
            />
            {isWeek ? (
              <ReferenceLine
                y={AVERAGE}
                stroke="green-500"
                strokeDasharray="3 3"
              />
            ) : null}
            {CATEGORIES.map((category, position) => (
              <Bar
                isAnimationActive={false}
                key={category}
                dataKey={category}
                stackId="a"
                fill={chartConfig[category].color}
                radius={position === CATEGORIES.length - 1 ? [5, 5, 0, 0] : 0}
                maxBarSize={isWeek ? 34 : 10}
              >
                {isWeek
                  ? data.map((item, index) => (
                      <Cell
                        key={item.label}
                        fillOpacity={
                          selected === null || selected === index ? 1 : 0.3
                        }
                      />
                    ))
                  : null}
              </Bar>
            ))}
          </BarChart>
        </ChartContainer>
        <View style={styles.stats}>
          {CATEGORIES.map((category) => (
            <View key={category} accessible style={styles.stat}>
              <View style={styles.statLabel}>
                <View
                  style={[
                    styles.dot,
                    { backgroundColor: tone(colors, SWATCH[category]) },
                  ]}
                />
                <Text
                  numberOfLines={1}
                  style={[styles.shrink, { color: colors.mutedForeground }]}
                >
                  {chartConfig[category].label}
                </Text>
              </View>
              <Text style={styles.statValue}>
                {formatMinutes(categories[category])}
              </Text>
            </View>
          ))}
        </View>
        <View>
          <Text style={[styles.section, { color: colors.mutedForeground }]}>
            Most used
          </Text>
          {apps.map((app) => (
            <View
              key={app.name}
              accessible
              style={[styles.app, { borderTopColor: colors.border }]}
            >
              <Text numberOfLines={1} style={styles.appName}>
                {app.name}
              </Text>
              <View
                style={[styles.track, { backgroundColor: colors.secondary }]}
              >
                <View
                  style={[
                    styles.fill,
                    {
                      width: `${(app.minutes / longest) * 100}%`,
                      backgroundColor: tone(colors, SWATCH[app.category]),
                    },
                  ]}
                />
              </View>
              <Text style={[styles.time, { color: colors.mutedForeground }]}>
                {formatMinutes(app.minutes)}
              </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/BarChartInteractive.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/BarChartInteractive.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 { BarChartInteractive } from "@/components/charts/bar-chart-interactive"
```

```tsx
<BarChartInteractive />
```

**SwiftUI**

```swift
import SwiftUI

struct BarInteractiveExample: View {
  var body: some View {
    BarChartInteractive()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarInteractiveExample() {
    BarChartInteractive()
}
```



## Bar Chart Labeled

A single bar series with each value printed above its bar and no grid lines.

Source: https://suiss.app/ui/docs/charts/bar-chart#labeled

**React**

**Example**

```tsx title="components/charts/bar-chart-labeled.tsx"
"use client"

import { Bar, BarChart, LabelList, 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 BarChartLabeled() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>The value sits above each bar</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 22, right: 4, left: 4, bottom: 0 }}
          >
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar
              dataKey="desktop"
              fill="var(--color-desktop)"
              radius={6}
              maxBarSize={36}
            >
              <LabelList
                position="top"
                offset={8}
                className="fill-foreground font-semibold"
                fontSize={12}
              />
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A single bar series with each value printed above its bar and no grid lines. Use it when exact numbers matter and there are few enough bars for the labels to fit.

Replace `chartData`, point each `dataKey` at your fields and set the label and color in `chartConfig`. The `position` prop on `LabelList` moves the labels, for example inside the bar; raise the chart's top margin if larger labels get clipped. Focus the chart and use the arrow keys to move the tooltip between bars.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-labeled
```

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 bar-chart-labeled
```

**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/bar-chart-labeled.tsx"
"use client"

import { Bar, BarChart, LabelList, 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 BarChartLabeled() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>The value sits above each bar</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 22, right: 4, left: 4, bottom: 0 }}
          >
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar
              dataKey="desktop"
              fill="var(--color-desktop)"
              radius={6}
              maxBarSize={36}
            >
              <LabelList
                position="top"
                offset={8}
                className="fill-foreground font-semibold"
                fontSize={12}
              />
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartLabeled } from "@/components/charts/bar-chart-labeled"
```

```tsx
<BarChartLabeled />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-labeled.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  LabelList,
  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 BarChartLabeled() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>The value sits above each bar</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 22, right: 4, left: 4, bottom: 0 }}
          >
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36}>
              <LabelList position="top" offset={8} />
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/BarChartLabeled.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 BarChartLabeled: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Labeled", description: "The value sits above each bar")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                BarMark(x: .value("Month", chartData[index].month), y: .value("Desktop", chartData[index].desktop * progress), width: .fixed(36))
                  .clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
                  .foregroundStyle(chartConfig.color("desktop"))
                  .annotation(position: .top, spacing: 8) {
                    Text(chartData[index].desktop, format: .number)
                      .scaledFont(TextStyle.xs, weight: .semibold)
                      .foregroundStyle(EsuissColor.foreground)
                      .opacity(progress < 1 ? 0 : 1)
                  }
                ChartAnchorMark(x: .value("Month", chartData[index].month), y: .value("Desktop", chartData[index].desktop))
              }
            }
            .chartYScale(range: .plotDimension(endPadding: 22))
            .chartXAxis { ChartAxis.x(values: chartData.map(\.month)) { String($0.prefix(3)) } }
            .chartYAxis(.hidden)
            .chartTooltip(
              x: chartData.map(\.month),
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Labeled",
              items: { [ChartTooltipItem("desktop", value: chartData[$0].desktop)] }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartLabeled.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.BarChart
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.ChartLabelList
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.theme.EsuissTheme

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

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

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

@Composable
fun BarChartLabeled(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Labeled", description = "The value sits above each bar")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 22.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    accessibilityLabel = "Labeled",
                ) {
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip(cursor = null) { ChartTooltipContent(hideLabel = true) }
                    Bar(
                        "desktop",
                        value = { it.desktop },
                        radius = ChartRadius(6.dp),
                        maxBarSize = 36.dp,
                        labelList = ChartLabelList(offset = 8.dp, color = colors.foreground),
                    )
                }
            }
        }
    }
}
```

**React Native**

One rounded bar per month with a `LabelList` placed at the top of each bar, so values are readable without touching the chart. There is no grid; a month axis and a tooltip remain.

Replace `chartData` with your records and change each `dataKey` to match your fields. Change `position` and `offset` on the `LabelList` to move the labels. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-labeled
```

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 bar-chart-labeled
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-labeled
```

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 bar-chart-labeled --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-labeled
```

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 bar-chart-labeled --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/bar-chart-labeled.tsx`:

- `uniwind/components/charts/bar-chart-labeled.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/bar-chart-labeled.tsx`:

```tsx title="nativewind/components/charts/bar-chart-labeled.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  LabelList,
  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 BarChartLabeled() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>The value sits above each bar</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 22, right: 4, left: 4, bottom: 0 }}
          >
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36}>
              <LabelList position="top" offset={8} />
            </Bar>
          </BarChart>
        </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/bar-chart-labeled.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-labeled.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  LabelList,
  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 BarChartLabeled() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Labeled</CardTitle>
        <CardDescription>The value sits above each bar</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Labeled"
          style={{ height: 192 }}
        >
          <BarChart
            data={chartData}
            margin={{ top: 22, right: 4, left: 4, bottom: 0 }}
          >
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={6} maxBarSize={36}>
              <LabelList position="top" offset={8} />
            </Bar>
          </BarChart>
        </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/BarChartLabeled.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/BarChartLabeled.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 { BarChartLabeled } from "@/components/charts/bar-chart-labeled"
```

```tsx
<BarChartLabeled />
```

**SwiftUI**

```swift
import SwiftUI

struct BarLabeledExample: View {
  var body: some View {
    BarChartLabeled()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarLabeledExample() {
    BarChartLabeled()
}
```



## Bar Chart Multiple

Two series drawn as grouped bars side by side for each month.

Source: https://suiss.app/ui/docs/charts/bar-chart#multiple

**React**

**Example**

```tsx title="components/charts/bar-chart-multiple.tsx"
"use client"

import { Bar, BarChart, 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 BarChartMultiple() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Multiple series</CardTitle>
        <CardDescription>Desktop and mobile side by side</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            barGap={3}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent indicator="dashed" />}
            />
            <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
            <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two series drawn as grouped bars side by side for each month. Pick it over the stacked variant when readers need to compare the series directly rather than see their total.

Replace `chartData` and rename the series keys in the data, the two `Bar` elements and `chartConfig`, and add a `Bar` for another series. `barGap` sets the space between bars in a group. Beyond three series or a dozen categories, consider stacked bars or a line chart. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-multiple
```

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 bar-chart-multiple
```

**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/bar-chart-multiple.tsx"
"use client"

import { Bar, BarChart, 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 BarChartMultiple() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Multiple series</CardTitle>
        <CardDescription>Desktop and mobile side by side</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            barGap={3}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent indicator="dashed" />}
            />
            <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
            <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartMultiple } from "@/components/charts/bar-chart-multiple"
```

```tsx
<BarChartMultiple />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-multiple.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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

export function BarChartMultiple() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Multiple series</CardTitle>
        <CardDescription>Desktop and mobile side by side</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Multiple series"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            barGap={3}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent indicator="dashed" />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={4} />
            <Bar dataKey="mobile" fill="chart-2" radius={4} />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/BarChartMultiple.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 BarChartMultiple: View {
  @State private var selection: Int?

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Multiple series", description: "Desktop and mobile side by side")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartConfig.keys, id: \.self) { key in
                ForEach(chartData.indices, id: \.self) { index in
                  BarMark(x: .value("Month", chartData[index].month), y: .value("Visitors", value(key, index) * progress))
                    .position(by: .value("Series", key), span: .ratio(0.95))
                    .clipShape(RoundedRectangle(cornerRadius: 4, style: .continuous))
                    .foregroundStyle(chartConfig.color(key))
                  ChartAnchorMark(x: .value("Month", chartData[index].month), y: .value("Visitors", value(key, index)))
                }
              }
            }
            .chartXAxis { ChartAxis.x(values: chartData.map(\.month)) { String($0.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: chartData.map(\.month),
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Multiple series",
              items: { index in chartConfig.keys.map { ChartTooltipItem($0, value: value($0, index)) } }
            ) { payload in
              ChartTooltipContent(payload, indicator: .dashed)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartMultiple.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.BarChart
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.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.components.ChartTooltipIndicator

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

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

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

@Composable
fun BarChartMultiple(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Multiple series", description = "Desktop and mobile side by side")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    barGap = 3.dp,
                    accessibilityLabel = "Multiple series",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip(cursor = null) { ChartTooltipContent(indicator = ChartTooltipIndicator.Dashed) }
                    Bar("desktop", value = { it.desktop }, radius = ChartRadius(4.dp))
                    Bar("mobile", value = { it.mobile }, radius = ChartRadius(4.dp))
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

Two `Bar` series sit next to each other in every month, separated by a small `barGap`. The tooltip lists both values with a dashed indicator.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Add a `Bar` and a `chartConfig` entry for each extra series. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-multiple
```

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 bar-chart-multiple
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-multiple
```

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 bar-chart-multiple --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-multiple
```

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 bar-chart-multiple --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/bar-chart-multiple.tsx`:

- `uniwind/components/charts/bar-chart-multiple.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/bar-chart-multiple.tsx`:

```tsx title="nativewind/components/charts/bar-chart-multiple.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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

export function BarChartMultiple() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Multiple series</CardTitle>
        <CardDescription>Desktop and mobile side by side</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Multiple series"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            barGap={3}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent indicator="dashed" />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={4} />
            <Bar dataKey="mobile" fill="chart-2" radius={4} />
          </BarChart>
        </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/bar-chart-multiple.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-multiple.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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

export function BarChartMultiple() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Multiple series</CardTitle>
        <CardDescription>Desktop and mobile side by side</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Multiple series"
          style={{ height: 192 }}
        >
          <BarChart
            data={chartData}
            barGap={3}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent indicator="dashed" />}
            />
            <Bar dataKey="desktop" fill="chart-1" radius={4} />
            <Bar dataKey="mobile" fill="chart-2" radius={4} />
          </BarChart>
        </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/BarChartMultiple.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/BarChartMultiple.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 { BarChartMultiple } from "@/components/charts/bar-chart-multiple"
```

```tsx
<BarChartMultiple />
```

**SwiftUI**

```swift
import SwiftUI

struct BarMultipleExample: View {
  var body: some View {
    BarChartMultiple()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarMultipleExample() {
    BarChartMultiple()
}
```



## Bar Chart Negative

Monthly cash flow bars that turn green above zero and red below it, with a zero baseline.

Source: https://suiss.app/ui/docs/charts/bar-chart#negative

**React**

**Example**

```tsx title="components/charts/bar-chart-negative.tsx"
"use client"

import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  ReferenceLine,
  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", flow: 42 },
  { month: "February", flow: -18 },
  { month: "March", flow: 26 },
  { month: "April", flow: 55 },
  { month: "May", flow: -31 },
  { month: "June", flow: 12 },
  { month: "July", flow: 38 },
  { month: "August", flow: -9 },
  { month: "September", flow: 47 },
  { month: "October", flow: 21 },
  { month: "November", flow: -14 },
  { month: "December", flow: 60 },
]

const chartConfig = {
  flow: { label: "Cash flow" },
} satisfies ChartConfig

export function BarChartNegative() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Positive and negative</CardTitle>
        <CardDescription>Monthly cash flow · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={1}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ReferenceLine y={0} stroke="var(--input)" />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideIndicator />}
            />
            <Bar dataKey="flow" radius={4} maxBarSize={18}>
              {chartData.map((item) => (
                <Cell
                  key={item.month}
                  fill={
                    item.flow >= 0
                      ? "var(--color-green-500)"
                      : "var(--color-red-500)"
                  }
                />
              ))}
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Monthly cash flow where bars rise green above a zero line and drop red below it. Use it for any value that can be negative, such as profit, net change or deltas against a target.

Replace `chartData` and rename `flow` in the data, the bar and `chartConfig`. Each `Cell` picks its color from the sign of the value, so change the two colors there, and `interval` on the axis sets how many month labels show. Because colors are set per bar, the tooltip has no swatch, so keep the zero line to show the direction without color. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-negative
```

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 bar-chart-negative
```

**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/bar-chart-negative.tsx"
"use client"

import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  ReferenceLine,
  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", flow: 42 },
  { month: "February", flow: -18 },
  { month: "March", flow: 26 },
  { month: "April", flow: 55 },
  { month: "May", flow: -31 },
  { month: "June", flow: 12 },
  { month: "July", flow: 38 },
  { month: "August", flow: -9 },
  { month: "September", flow: 47 },
  { month: "October", flow: 21 },
  { month: "November", flow: -14 },
  { month: "December", flow: 60 },
]

const chartConfig = {
  flow: { label: "Cash flow" },
} satisfies ChartConfig

export function BarChartNegative() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Positive and negative</CardTitle>
        <CardDescription>Monthly cash flow · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-48 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickLine={false}
              axisLine={false}
              tickMargin={8}
              interval={1}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ReferenceLine y={0} stroke="var(--input)" />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideIndicator />}
            />
            <Bar dataKey="flow" radius={4} maxBarSize={18}>
              {chartData.map((item) => (
                <Cell
                  key={item.month}
                  fill={
                    item.flow >= 0
                      ? "var(--color-green-500)"
                      : "var(--color-red-500)"
                  }
                />
              ))}
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartNegative } from "@/components/charts/bar-chart-negative"
```

```tsx
<BarChartNegative />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-negative.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", flow: 42 },
  { month: "February", flow: -18 },
  { month: "March", flow: 26 },
  { month: "April", flow: 55 },
  { month: "May", flow: -31 },
  { month: "June", flow: 12 },
  { month: "July", flow: 38 },
  { month: "August", flow: -9 },
  { month: "September", flow: 47 },
  { month: "October", flow: 21 },
  { month: "November", flow: -14 },
  { month: "December", flow: 60 },
]

const chartConfig = {
  flow: { label: "Cash flow" },
} satisfies ChartConfig

export function BarChartNegative() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Positive and negative</CardTitle>
        <CardDescription>Monthly cash flow · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Positive and negative"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={1}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ReferenceLine y={0} stroke="input" />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideIndicator />}
            />
            <Bar dataKey="flow" radius={4} maxBarSize={18}>
              {chartData.map((item) => (
                <Cell
                  key={item.month}
                  fill={item.flow >= 0 ? "green-500" : "red-500"}
                />
              ))}
            </Bar>
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

private let chartData: [(month: String, flow: Double)] = [
  ("January", 42), ("February", -18), ("March", 26), ("April", 55), ("May", -31), ("June", 12),
  ("July", 38), ("August", -9), ("September", 47), ("October", 21), ("November", -14), ("December", 60),
]

private let chartConfig: ChartConfig = [
  "flow": .init("Cash flow"),
]

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

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Positive and negative", description: "Monthly cash flow · thousands")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              RuleMark(y: .value("Zero", 0))
                .lineStyle(StrokeStyle(lineWidth: 1))
                .foregroundStyle(EsuissColor.input)
              ForEach(chartData.indices, id: \.self) { index in
                BarMark(x: .value("Month", chartData[index].month), y: .value("Flow", chartData[index].flow * progress), width: .fixed(18))
                  .clipShape(RoundedRectangle(cornerRadius: 4, style: .continuous))
                  .foregroundStyle(chartData[index].flow >= 0 ? Palette.green500 : Palette.red500)
                ChartAnchorMark(x: .value("Month", chartData[index].month), y: .value("Flow", chartData[index].flow))
              }
            }
            .chartXAxis { ChartAxis.x(values: chartData.indices.filter { $0.isMultiple(of: 2) }.map { chartData[$0].month }) { String($0.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: chartData.map(\.month),
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Positive and negative",
              items: { [ChartTooltipItem("flow", value: chartData[$0].flow)] }
            ) { payload in
              ChartTooltipContent(payload, hideIndicator: true)
            }
          }
        }
        .frame(height: 192)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartNegative.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.BarChart
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.ChartCell
import com.esuiss.ui.components.ChartConfig
import com.esuiss.ui.components.ChartConfigItem
import com.esuiss.ui.components.ChartContainer
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette

private class CashFlow(val month: String, val flow: Double)

private val chartData = listOf(
    CashFlow("January", 42.0),
    CashFlow("February", -18.0),
    CashFlow("March", 26.0),
    CashFlow("April", 55.0),
    CashFlow("May", -31.0),
    CashFlow("June", 12.0),
    CashFlow("July", 38.0),
    CashFlow("August", -9.0),
    CashFlow("September", 47.0),
    CashFlow("October", 21.0),
    CashFlow("November", -14.0),
    CashFlow("December", 60.0),
)

private val chartConfig = ChartConfig(
    "flow" to ChartConfigItem("Cash flow"),
)

@Composable
fun BarChartNegative(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Positive and negative", description = "Monthly cash flow · thousands")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(192.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    accessibilityLabel = "Positive and negative",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 1, tickFormatter = { it.take(3) })
                    ReferenceLine(0.0, stroke = colors.input)
                    ChartTooltip(cursor = null) { ChartTooltipContent(hideIndicator = true) }
                    Bar(
                        "flow",
                        value = { it.flow },
                        radius = ChartRadius(4.dp),
                        maxBarSize = 18.dp,
                        cells = { index -> ChartCell(if (chartData[index].flow >= 0) Palette.green500 else Palette.red500) },
                    )
                }
            }
        }
    }
}
```

**React Native**

One bar per month, colored per value through a `Cell`: green when the flow is positive and red when it is negative. A `ReferenceLine` at zero anchors the bars, and the month axis shows every other label.

Replace `chartData` with your months and signed `flow` values. Change the colors in the `Cell` `fill` expression. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-negative
```

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 bar-chart-negative
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-negative
```

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 bar-chart-negative --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-chart-negative
```

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 bar-chart-negative --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/bar-chart-negative.tsx`:

- `uniwind/components/charts/bar-chart-negative.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/bar-chart-negative.tsx`:

```tsx title="nativewind/components/charts/bar-chart-negative.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", flow: 42 },
  { month: "February", flow: -18 },
  { month: "March", flow: 26 },
  { month: "April", flow: 55 },
  { month: "May", flow: -31 },
  { month: "June", flow: 12 },
  { month: "July", flow: 38 },
  { month: "August", flow: -9 },
  { month: "September", flow: 47 },
  { month: "October", flow: 21 },
  { month: "November", flow: -14 },
  { month: "December", flow: 60 },
]

const chartConfig = {
  flow: { label: "Cash flow" },
} satisfies ChartConfig

export function BarChartNegative() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Positive and negative</CardTitle>
        <CardDescription>Monthly cash flow · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Positive and negative"
          className="h-48 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={1}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ReferenceLine y={0} stroke="input" />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideIndicator />}
            />
            <Bar dataKey="flow" radius={4} maxBarSize={18}>
              {chartData.map((item) => (
                <Cell
                  key={item.month}
                  fill={item.flow >= 0 ? "green-500" : "red-500"}
                />
              ))}
            </Bar>
          </BarChart>
        </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/bar-chart-negative.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-negative.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  CartesianGrid,
  Cell,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  ReferenceLine,
  XAxis,
} from "@/components/ui/chart"

const chartData = [
  { month: "January", flow: 42 },
  { month: "February", flow: -18 },
  { month: "March", flow: 26 },
  { month: "April", flow: 55 },
  { month: "May", flow: -31 },
  { month: "June", flow: 12 },
  { month: "July", flow: 38 },
  { month: "August", flow: -9 },
  { month: "September", flow: 47 },
  { month: "October", flow: 21 },
  { month: "November", flow: -14 },
  { month: "December", flow: 60 },
]

const chartConfig = {
  flow: { label: "Cash flow" },
} satisfies ChartConfig

export function BarChartNegative() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Positive and negative</CardTitle>
        <CardDescription>Monthly cash flow · thousands</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Positive and negative"
          style={{ height: 192 }}
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={1}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ReferenceLine y={0} stroke="input" />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideIndicator />}
            />
            <Bar dataKey="flow" radius={4} maxBarSize={18}>
              {chartData.map((item) => (
                <Cell
                  key={item.month}
                  fill={item.flow >= 0 ? "green-500" : "red-500"}
                />
              ))}
            </Bar>
          </BarChart>
        </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/BarChartNegative.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/BarChartNegative.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 { BarChartNegative } from "@/components/charts/bar-chart-negative"
```

```tsx
<BarChartNegative />
```

**SwiftUI**

```swift
import SwiftUI

struct BarNegativeExample: View {
  var body: some View {
    BarChartNegative()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarNegativeExample() {
    BarChartNegative()
}
```



## Bar Chart Range

A weather forecast where each horizontal pill spans the day's low and high on a shared gradient scale.

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

**React**

**Example**

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

import * as React from "react"
import { Bar, BarChart, 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 = [
  { day: "Today", low: 14, high: 22 },
  { day: "Wed", low: 13, high: 21 },
  { day: "Thu", low: 15, high: 24 },
  { day: "Fri", low: 16, high: 25 },
  { day: "Sat", low: 14, high: 20 },
  { day: "Sun", low: 11, high: 17 },
  { day: "Mon", low: 10, high: 16 },
  { day: "Tue", low: 12, high: 19 },
].map((item) => ({ ...item, range: [item.low, item.high] }))

const chartConfig = {
  range: { label: "Temperature" },
} satisfies ChartConfig

export function BarChartRange() {
  const id = React.useId()

  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>8-day forecast</CardTitle>
        <CardDescription>Each bar spans the low and high</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-60 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            layout="vertical"
            barCategoryGap={7}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <defs>
              <linearGradient id={id} x1="0" y1="0" x2="1" y2="0">
                <stop offset="0%" stopColor="var(--color-teal-500)" />
                <stop offset="55%" stopColor="var(--color-yellow-500)" />
                <stop offset="100%" stopColor="var(--color-orange-500)" />
              </linearGradient>
            </defs>
            <YAxis
              dataKey="day"
              type="category"
              tickLine={false}
              axisLine={false}
              width="auto"
              tick={{ className: "fill-foreground font-semibold" }}
            />
            <YAxis
              yAxisId="high"
              dataKey="high"
              type="category"
              orientation="right"
              tickLine={false}
              axisLine={false}
              width="auto"
              tick={{ className: "fill-foreground font-semibold" }}
              tickFormatter={(value: number) => `${value}°`}
            />
            <XAxis type="number" hide domain={[8, 27]} />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  formatter={(value) => (
                    <span className="font-semibold tabular-nums">
                      {Array.isArray(value)
                        ? `${value[0]}° to ${value[1]}°`
                        : value}
                    </span>
                  )}
                />
              }
            />
            <Bar
              dataKey="range"
              fill={`url(#${id})`}
              radius={99}
              background={{ fill: "var(--secondary)", radius: 99 }}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

A weather-app forecast where each horizontal pill spans a day's low to high temperature against a shared scale, with a colored gradient fill and the high on the right. Use floating range bars like these whenever each item has a minimum and a maximum.

Give each record a label, a `low` and a `high`; the chart derives the two-value `range` from them. Set the hidden value axis `domain` to cover your full range so pills line up across rows, and edit the gradient stops in the `defs` block to change the colors. The gradient runs across each pill, not the whole scale. Only the high is printed beside the bars; the low is in the tooltip.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-range.tsx"
"use client"

import * as React from "react"
import { Bar, BarChart, 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 = [
  { day: "Today", low: 14, high: 22 },
  { day: "Wed", low: 13, high: 21 },
  { day: "Thu", low: 15, high: 24 },
  { day: "Fri", low: 16, high: 25 },
  { day: "Sat", low: 14, high: 20 },
  { day: "Sun", low: 11, high: 17 },
  { day: "Mon", low: 10, high: 16 },
  { day: "Tue", low: 12, high: 19 },
].map((item) => ({ ...item, range: [item.low, item.high] }))

const chartConfig = {
  range: { label: "Temperature" },
} satisfies ChartConfig

export function BarChartRange() {
  const id = React.useId()

  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>8-day forecast</CardTitle>
        <CardDescription>Each bar spans the low and high</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-60 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            layout="vertical"
            barCategoryGap={7}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <defs>
              <linearGradient id={id} x1="0" y1="0" x2="1" y2="0">
                <stop offset="0%" stopColor="var(--color-teal-500)" />
                <stop offset="55%" stopColor="var(--color-yellow-500)" />
                <stop offset="100%" stopColor="var(--color-orange-500)" />
              </linearGradient>
            </defs>
            <YAxis
              dataKey="day"
              type="category"
              tickLine={false}
              axisLine={false}
              width="auto"
              tick={{ className: "fill-foreground font-semibold" }}
            />
            <YAxis
              yAxisId="high"
              dataKey="high"
              type="category"
              orientation="right"
              tickLine={false}
              axisLine={false}
              width="auto"
              tick={{ className: "fill-foreground font-semibold" }}
              tickFormatter={(value: number) => `${value}°`}
            />
            <XAxis type="number" hide domain={[8, 27]} />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  formatter={(value) => (
                    <span className="font-semibold tabular-nums">
                      {Array.isArray(value)
                        ? `${value[0]}° to ${value[1]}°`
                        : value}
                    </span>
                  )}
                />
              }
            />
            <Bar
              dataKey="range"
              fill={`url(#${id})`}
              radius={99}
              background={{ fill: "var(--secondary)", radius: 99 }}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartRange } from "@/components/charts/bar-chart-range"
```

```tsx
<BarChartRange />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-range.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { day: "Today", low: 14, high: 22 },
  { day: "Wed", low: 13, high: 21 },
  { day: "Thu", low: 15, high: 24 },
  { day: "Fri", low: 16, high: 25 },
  { day: "Sat", low: 14, high: 20 },
  { day: "Sun", low: 11, high: 17 },
  { day: "Mon", low: 10, high: 16 },
  { day: "Tue", low: 12, high: 19 },
].map((item) => ({ ...item, range: [item.low, item.high] }))

const chartConfig = {
  range: { label: "Temperature" },
} satisfies ChartConfig

export function BarChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>8-day forecast</CardTitle>
        <CardDescription>Each bar spans the low and high</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="8-day forecast"
          className="h-60 w-full"
        >
          <BarChart
            data={chartData}
            layout="vertical"
            barCategoryGap={7}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="day"
              type="category"
              width="auto"
              tickClassName="text-foreground font-semibold"
            />
            <YAxis
              dataKey="high"
              type="category"
              orientation="right"
              width="auto"
              tickClassName="text-foreground font-semibold"
              tickFormatter={(value) => `${value}°`}
            />
            <XAxis type="number" hide domain={[8, 27]} />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  formatter={(value) => (
                    <Text className="font-semibold tabular-nums">
                      {typeof value === "number"
                        ? String(value)
                        : `${value[0]}° to ${value[1]}°`}
                    </Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="range"
              fill={{
                direction: "horizontal",
                stops: [
                  { offset: 0, color: "chart-2" },
                  { offset: 0.55, color: "yellow-500" },
                  { offset: 1, color: "chart-4" },
                ],
              }}
              radius={99}
              background={{ fill: "secondary", radius: 99 }}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

private let chartData: [(day: String, low: Double, high: Double)] = [
  ("Today", 14, 22), ("Wed", 13, 21), ("Thu", 15, 24), ("Fri", 16, 25),
  ("Sat", 14, 20), ("Sun", 11, 17), ("Mon", 10, 16), ("Tue", 12, 19),
]

private let chartConfig: ChartConfig = [
  "range": .init("Temperature"),
]

private func high(_ day: String) -> String {
  chartData.first { $0.day == day }.map { "\(Int($0.high))°" } ?? ""
}

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

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("8-day forecast", description: "Each bar spans the low and high")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                BarMark(xStart: .value("Low", 8), xEnd: .value("High", 27), y: .value("Day", chartData[index].day), height: .ratio(0.76))
                  .clipShape(Capsule())
                  .foregroundStyle(EsuissColor.secondary)
                BarMark(xStart: .value("Low", chartData[index].low), xEnd: .value("High", chartData[index].low + (chartData[index].high - chartData[index].low) * progress), y: .value("Day", chartData[index].day), height: .ratio(0.76))
                  .clipShape(Capsule())
                  .foregroundStyle(LinearGradient(colors: [Palette.teal500, Palette.yellow500, Palette.orange500], startPoint: .leading, endPoint: .trailing))
              }
            }
            .chartXScale(domain: 8...27)
            .chartXAxis(.hidden)
            .chartYAxis {
              ChartAxis.y(values: chartData.map(\.day), edge: .leading, grid: false, emphasized: true) { $0 }
              ChartAxis.y(values: chartData.map(\.day), edge: .trailing, grid: false, emphasized: true) { high($0) }
            }
            .chartTooltip(
              y: chartData.map(\.day),
              selection: $selection,
              accessibilityLabel: "8-day forecast",
              items: { [ChartTooltipItem("range", value: chartData[$0].high)] }
            ) { payload in
              ChartTooltipContent(payload, hideIndicator: true) { (_: ChartTooltipItem) in
                Text(verbatim: "\(Int(chartData[payload.index].low))° to \(Int(chartData[payload.index].high))°")
                  .scaledFont(TextStyle.xs, weight: .semibold)
                  .monospacedDigit()
              }
            }
          }
        }
        .frame(height: 240)
      }
    }
  }
}
```

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

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.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.BarChart
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.ChartFill
import com.esuiss.ui.components.ChartLayout
import com.esuiss.ui.components.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Palette
import com.esuiss.ui.theme.Typography

private class ForecastDay(val day: String, val low: Int, val high: Int)

private val chartData = listOf(
    ForecastDay("Today", 14, 22),
    ForecastDay("Wed", 13, 21),
    ForecastDay("Thu", 15, 24),
    ForecastDay("Fri", 16, 25),
    ForecastDay("Sat", 14, 20),
    ForecastDay("Sun", 11, 17),
    ForecastDay("Mon", 10, 16),
    ForecastDay("Tue", 12, 19),
)

private val chartConfig = ChartConfig(
    "range" to ChartConfigItem("Temperature"),
)

@Composable
fun BarChartRange(modifier: Modifier = Modifier) {
    val colors = EsuissTheme.colors
    val tick = TextStyle(color = colors.foreground, fontWeight = FontWeight.SemiBold)
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("8-day forecast", description = "Each bar spans the low and high")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(240.dp),
            ) {
                BarChart(
                    chartData,
                    layout = ChartLayout.Vertical,
                    barCategoryGap = 7.dp,
                    margin = ChartMargin(0.dp, 0.dp, 0.dp, 0.dp),
                    accessibilityLabel = "8-day forecast",
                ) {
                    YAxis(label = { it.day }, tickStyle = tick)
                    YAxis(label = { "${it.high}°" }, orientation = ChartAxisOrientation.Right, tickStyle = tick)
                    XAxis(domain = 8.0..27.0)
                    ChartTooltip(cursor = null) {
                        ChartTooltipContent(
                            hideIndicator = true,
                            formatter = { item ->
                                BasicText(
                                    "${item.base?.toInt()}° to ${item.value.toInt()}°",
                                    style = Typography.xs.copy(color = colors.foreground, fontWeight = FontWeight.SemiBold, fontFeatureSettings = "tnum"),
                                )
                            },
                        )
                    }
                    Bar(
                        "range",
                        value = { it.high.toDouble() },
                        base = { it.low.toDouble() },
                        fill = ChartFill.HorizontalGradient(listOf(0f to colors.chart2, 0.55f to Palette.yellow500, 1f to colors.chart4)),
                        radius = ChartRadius(99.dp),
                        background = colors.secondary,
                    )
                }
            }
        }
    }
}
```

**React Native**

A horizontal `BarChart` whose `range` values are `[low, high]` pairs, so each bar floats between the two temperatures. Bars use a teal-to-orange gradient over a full-width track, day names sit on the left and highs on the right. The tooltip shows the range in degrees.

Replace `chartData` with your days and `low` and `high` values; the `range` pair is derived from them. Adjust the hidden `XAxis` `domain` to fit your temperature range. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-range
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-range --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-range.tsx`:

- `uniwind/components/charts/bar-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/bar-chart-range.tsx`:

```tsx title="nativewind/components/charts/bar-chart-range.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"

const chartData = [
  { day: "Today", low: 14, high: 22 },
  { day: "Wed", low: 13, high: 21 },
  { day: "Thu", low: 15, high: 24 },
  { day: "Fri", low: 16, high: 25 },
  { day: "Sat", low: 14, high: 20 },
  { day: "Sun", low: 11, high: 17 },
  { day: "Mon", low: 10, high: 16 },
  { day: "Tue", low: 12, high: 19 },
].map((item) => ({ ...item, range: [item.low, item.high] }))

const chartConfig = {
  range: { label: "Temperature" },
} satisfies ChartConfig

export function BarChartRange() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>8-day forecast</CardTitle>
        <CardDescription>Each bar spans the low and high</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="8-day forecast"
          className="h-60 w-full"
        >
          <BarChart
            data={chartData}
            layout="vertical"
            barCategoryGap={7}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="day"
              type="category"
              width="auto"
              tickClassName="text-foreground font-semibold"
            />
            <YAxis
              dataKey="high"
              type="category"
              orientation="right"
              width="auto"
              tickClassName="text-foreground font-semibold"
              tickFormatter={(value) => `${value}°`}
            />
            <XAxis type="number" hide domain={[8, 27]} />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  formatter={(value) => (
                    <Text className="font-semibold tabular-nums">
                      {typeof value === "number"
                        ? String(value)
                        : `${value[0]}° to ${value[1]}°`}
                    </Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="range"
              fill={{
                direction: "horizontal",
                stops: [
                  { offset: 0, color: "chart-2" },
                  { offset: 0.55, color: "yellow-500" },
                  { offset: 1, color: "chart-4" },
                ],
              }}
              radius={99}
              background={{ fill: "secondary", radius: 99 }}
            />
          </BarChart>
        </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/bar-chart-range.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-range.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/components/ui/chart"
import { Text } from "@/components/ui/text"
import { useTheme } from "@/components/ui/theme"

const chartData = [
  { day: "Today", low: 14, high: 22 },
  { day: "Wed", low: 13, high: 21 },
  { day: "Thu", low: 15, high: 24 },
  { day: "Fri", low: 16, high: 25 },
  { day: "Sat", low: 14, high: 20 },
  { day: "Sun", low: 11, high: 17 },
  { day: "Mon", low: 10, high: 16 },
  { day: "Tue", low: 12, high: 19 },
].map((item) => ({ ...item, range: [item.low, item.high] }))

const chartConfig = {
  range: { label: "Temperature" },
} satisfies ChartConfig

export function BarChartRange() {
  const { colors } = useTheme()
  const tickStyle = { color: colors.foreground, fontWeight: "600" } as const
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>8-day forecast</CardTitle>
        <CardDescription>Each bar spans the low and high</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="8-day forecast"
          style={{ height: 240 }}
        >
          <BarChart
            data={chartData}
            layout="vertical"
            barCategoryGap={7}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <YAxis
              dataKey="day"
              type="category"
              width="auto"
              tickStyle={tickStyle}
            />
            <YAxis
              dataKey="high"
              type="category"
              orientation="right"
              width="auto"
              tickStyle={tickStyle}
              tickFormatter={(value) => `${value}°`}
            />
            <XAxis type="number" hide domain={[8, 27]} />
            <ChartTooltip
              cursor={false}
              content={
                <ChartTooltipContent
                  hideIndicator
                  formatter={(value) => (
                    <Text
                      style={{
                        fontWeight: "600",
                        fontVariant: ["tabular-nums"],
                      }}
                    >
                      {typeof value === "number"
                        ? String(value)
                        : `${value[0]}° to ${value[1]}°`}
                    </Text>
                  )}
                />
              }
            />
            <Bar
              dataKey="range"
              fill={{
                direction: "horizontal",
                stops: [
                  { offset: 0, color: "chart-2" },
                  { offset: 0.55, color: "yellow-500" },
                  { offset: 1, color: "chart-4" },
                ],
              }}
              radius={99}
              background={{ fill: "secondary", radius: 99 }}
            />
          </BarChart>
        </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/BarChartRange.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/BarChartRange.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 { BarChartRange } from "@/components/charts/bar-chart-range"
```

```tsx
<BarChartRange />
```

**SwiftUI**

```swift
import SwiftUI

struct BarRangeExample: View {
  var body: some View {
    BarChartRange()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarRangeExample() {
    BarChartRange()
}
```



## Bar Chart Stacked

Two series stacked into one bar per month, with a legend below the plot.

Source: https://suiss.app/ui/docs/charts/bar-chart#stacked

**React**

**Example**

```tsx title="components/charts/bar-chart-stacked.tsx"
"use client"

import { Bar, BarChart, 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 BarChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>With a legend</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-56 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar
              dataKey="desktop"
              stackId="a"
              fill="var(--color-desktop)"
              radius={[0, 0, 4, 4]}
              maxBarSize={36}
            />
            <Bar
              dataKey="mobile"
              stackId="a"
              fill="var(--color-mobile)"
              radius={[4, 4, 0, 0]}
              maxBarSize={36}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

Two series stacked into one bar per month, with a legend under the plot. Use it when the total per month matters as well as how each series contributes to it.

Replace `chartData` and rename the series keys in the data, both `Bar` elements and `chartConfig`; the legend reads labels and colors from the config. Every bar in the stack needs the same `stackId`, and the first one sits at the bottom. If you add a series, move the rounded top corners via `radius` to the top bar. Focus the chart and use the arrow keys to move the tooltip between months.

### Installation

**Command**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-stacked.tsx"
"use client"

import { Bar, BarChart, 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 BarChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>With a legend</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          className="aspect-auto h-56 w-full"
        >
          <BarChart
            accessibilityLayer
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, 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
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar
              dataKey="desktop"
              stackId="a"
              fill="var(--color-desktop)"
              radius={[0, 0, 4, 4]}
              maxBarSize={36}
            />
            <Bar
              dataKey="mobile"
              stackId="a"
              fill="var(--color-mobile)"
              radius={[4, 4, 0, 0]}
              maxBarSize={36}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

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

### Usage

```tsx
import { BarChartStacked } from "@/components/charts/bar-chart-stacked"
```

```tsx
<BarChartStacked />
```

**React Native, SwiftUI, Jetpack Compose**

```tsx title="uniwind/components/charts/bar-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>With a legend</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          className="h-56 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar
              dataKey="desktop"
              stackId="a"
              fill="chart-1"
              radius={[0, 0, 4, 4]}
              maxBarSize={36}
            />
            <Bar
              dataKey="mobile"
              stackId="a"
              fill="chart-2"
              radius={[4, 4, 0, 0]}
              maxBarSize={36}
            />
          </BarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}
```

```swift title="swift/Charts/BarChartStacked.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),
]

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

  public init() {}

  public var body: some View {
    Card(.filled, size: .sm) {
      CardHeader("Stacked", description: "With a legend")
      CardContent {
        ChartContainer(config: chartConfig) {
          ChartAnimator(animationDuration: 400) { progress in
            Chart {
              ForEach(chartData.indices, id: \.self) { index in
                let item = chartData[index]
                BarMark(x: .value("Month", item.month), yStart: .value("Start", 0), yEnd: .value("Desktop", item.desktop * progress), width: .fixed(36))
                  .clipShape(UnevenRoundedRectangle(bottomLeadingRadius: 4, bottomTrailingRadius: 4, style: .continuous))
                  .foregroundStyle(chartConfig.color("desktop"))
                BarMark(x: .value("Month", item.month), yStart: .value("Start", item.desktop * progress), yEnd: .value("Mobile", (item.desktop + item.mobile) * progress), width: .fixed(36))
                  .clipShape(UnevenRoundedRectangle(topLeadingRadius: 4, topTrailingRadius: 4, style: .continuous))
                  .foregroundStyle(chartConfig.color("mobile"))
                ChartAnchorMark(x: .value("Month", item.month), y: .value("Mobile", item.desktop + item.mobile))
              }
            }
            .chartXAxis { ChartAxis.x(values: chartData.map(\.month)) { String($0.prefix(3)) } }
            .chartYAxis { ChartAxis.grid() }
            .chartTooltip(
              x: chartData.map(\.month),
              selection: $selection,
              cursor: false,
              accessibilityLabel: "Stacked",
              items: { index in
                [
                  ChartTooltipItem("desktop", value: chartData[index].desktop),
                  ChartTooltipItem("mobile", value: chartData[index].mobile),
                ]
              }
            ) { payload in
              ChartTooltipContent(payload, hideLabel: true)
            }
          }
          ChartLegendContent()
        }
        .frame(height: 224)
      }
    }
  }
}
```

```kt title="kotlin/charts/BarChartStacked.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.BarChart
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.ChartMargin
import com.esuiss.ui.components.ChartRadius
import com.esuiss.ui.components.ChartTooltipContent

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

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

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

@Composable
fun BarChartStacked(modifier: Modifier = Modifier) {
    Card(modifier, variant = CardVariant.Filled, size = CardSize.Sm) {
        CardHeader("Stacked", description = "With a legend")
        CardContent {
            ChartContainer(
                chartConfig,
                Modifier
                    .fillMaxWidth()
                    .height(224.dp),
            ) {
                BarChart(
                    chartData,
                    margin = ChartMargin(top = 10.dp, right = 4.dp, bottom = 0.dp, left = 4.dp),
                    accessibilityLabel = "Stacked",
                ) {
                    CartesianGrid(strokeDasharray = listOf(2f, 4f))
                    XAxis(label = { it.month }, tickMargin = 8.dp, interval = 0, tickFormatter = { it.take(3) })
                    ChartTooltip(cursor = null) { ChartTooltipContent(hideLabel = true) }
                    ChartLegend()
                    Bar(
                        "desktop",
                        value = { it.desktop },
                        radius = ChartRadius(0.dp, 0.dp, 4.dp, 4.dp),
                        maxBarSize = 36.dp,
                        stackId = "a",
                    )
                    Bar(
                        "mobile",
                        value = { it.mobile },
                        radius = ChartRadius(4.dp, 4.dp, 0.dp, 0.dp),
                        maxBarSize = 36.dp,
                        stackId = "a",
                    )
                }
            }
        }
    }
}
```

**React Native, Jetpack Compose**

Desktop and mobile bars share a `stackId`, so each column shows both parts and their total. Only the outer corners are rounded, and a legend below the plot names both series.

**React Native**

Replace `chartData` with your records and change each `dataKey` to match your fields. Add, rename or recolor series in `chartConfig` and add a `Bar` for each. The component takes no props.

**React Native, SwiftUI, Jetpack Compose**

### Installation

**Command**

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-stacked
```

**SwiftUI**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-chart-stacked --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx shadcn@latest add @esuiss/bar-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 bar-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/bar-chart-stacked.tsx`:

- `uniwind/components/charts/bar-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/bar-chart-stacked.tsx`:

```tsx title="nativewind/components/charts/bar-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>With a legend</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          className="h-56 w-full"
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar
              dataKey="desktop"
              stackId="a"
              fill="chart-1"
              radius={[0, 0, 4, 4]}
              maxBarSize={36}
            />
            <Bar
              dataKey="mobile"
              stackId="a"
              fill="chart-2"
              radius={[4, 4, 0, 0]}
              maxBarSize={36}
            />
          </BarChart>
        </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/bar-chart-stacked.tsx`:

```tsx title="stylesheet/components/charts/bar-chart-stacked.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  Bar,
  BarChart,
  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 BarChartStacked() {
  return (
    <Card variant="filled" size="sm">
      <CardHeader>
        <CardTitle>Stacked</CardTitle>
        <CardDescription>With a legend</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={chartConfig}
          accessibilityLabel="Stacked"
          style={{ height: 224 }}
        >
          <BarChart
            data={chartData}
            margin={{ top: 10, right: 4, left: 4, bottom: 0 }}
          >
            <CartesianGrid vertical={false} strokeDasharray="2 4" />
            <XAxis
              dataKey="month"
              tickMargin={8}
              interval={0}
              tickFormatter={(value: string) => value.slice(0, 3)}
            />
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar
              dataKey="desktop"
              stackId="a"
              fill="chart-1"
              radius={[0, 0, 4, 4]}
              maxBarSize={36}
            />
            <Bar
              dataKey="mobile"
              stackId="a"
              fill="chart-2"
              radius={[4, 4, 0, 0]}
              maxBarSize={36}
            />
          </BarChart>
        </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/BarChartStacked.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/BarChartStacked.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 { BarChartStacked } from "@/components/charts/bar-chart-stacked"
```

```tsx
<BarChartStacked />
```

**SwiftUI**

```swift
import SwiftUI

struct BarStackedExample: View {
  var body: some View {
    BarChartStacked()
  }
}
```

**Jetpack Compose**

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

@Composable
fun BarStackedExample() {
    BarChartStacked()
}
```

