Interactive example
Session share by deviceSynthetic percentages for each weekday
  • Desktop
  • Tablet
  • Phone
Use arrow keys to select a data point. Home selects the first point and End selects the last. Escape closes the value tooltip.
Mon
Desktop
46%
Tablet
18%
Phone
36%
View data table 5 rows
Session share by device
Data pointDesktopTabletPhone
Mon46%18%36%
Tue51%16%33%
Wed48%19%33%
Thu54%17%29%
Fri49%15%36%

Installation

terminal
bunx --bun shadcn@latest add https://apple-ui-eduardo.vercel.app/r/stacked-bar-chart.json

The registry includes the shared styles and dependencies. Import @/components/apple-ui/styles.css in your root layout once. For the package route, use the installation guide.

Usage

tsx
"use client";

import { StackedBarChart } from "@eduardoul/apple-ui";

const data = [
  { label: "Mon", desktop: 46, tablet: 18, phone: 36 },
  { label: "Tue", desktop: 51, tablet: 16, phone: 33 },
  { label: "Wed", desktop: 48, tablet: 19, phone: 33 },
  { label: "Thu", desktop: 54, tablet: 17, phone: 29 },
];

export function Example() {
  return (
    <StackedBarChart
      title="Session share by device"
      description="Synthetic percentages for each weekday"
      data={data}
      series={[
        { key: "desktop", label: "Desktop" },
        { key: "tablet", label: "Tablet" },
        { key: "phone", label: "Phone" },
      ]}
      valueFormatter={(value) => value + "%"}
    />
  );
}

Package imports use @eduardoul/apple-ui. Registry imports use @/components/apple-ui. Add "use client" to files that use state or event handlers.

API reference

PropertyTypeDefault
dataChartDatum[]required
seriesChartSeries[]required
labelKeystringlabel
titlestringrequired
descriptionstringundefined
heightnumbercomponent default
loadingbooleanfalse
errorstringundefined
emptyMessagestringNo data to display.
showTablebooleantrue
compactbooleanfalse
valueFormatter(value: number) => stringlocalized number
classNamestringundefined
styleReact.CSSPropertiesundefined

Use className and style to customize the component. The package includes full TypeScript definitions for its supported element properties and refs.

Design guidance

  • Use stacking when the total and its parts both answer useful questions.
  • Keep series order consistent across every bar so color and position retain meaning.
  • Use grouped bars when readers must compare every segment precisely. Only the first stacked segment shares a baseline.
Read Apple’s guidance

Accessibility

Give the chart a descriptive title and explain its units. Select a data point to read its values, or open the data table for the full dataset. Labels and values accompany color, and the chart adapts to reduced motion and appearance preferences. Test long labels, touch input and keyboard navigation with your own data.

Library styles support reduced motion, reduced transparency, increased contrast and forced colors. Read the accessibility foundation for the checks your application still needs.