Horizontal Bar Chart

Horizontal Bar Chart

Charts
Data Visualization

Visualize rankings, comparisons, and proportions with horizontal bars, rank badges, and change indicators.

Preview

Ranked horizontal bars with values and change indicators

Tasks by Project

Simple Variant

Minimal horizontal bars without ranks

Props

Component API reference

PropTypeDefaultDescription
data*{ label: string; value: number; change?: number }[]—Array of bar data
showRankbooleantrue (ranked)Show rank badges
showChangebooleantrue (ranked)Show change indicators
variant'ranked' | 'simple''ranked'Ranked rows or label-above-bar rows
maxnumber—Scale bars against this value instead of the largest
barHeightnumber32Bar height in pixels
formatValue(v: number) => string—Value formatter function
classNamestring—Additional CSS classes

Usage

Import and implementation examples

import { HorizontalBarChart } from '@/components/ui/horizontal-bar-chart'
const projects = [
{ label: 'Marketing', value: 4200, change: 12 },
{ label: 'Sales', value: 3100, change: -3 },
{ label: 'Product', value: 2800, change: 8 },
]
<HorizontalBarChart data={projects} />
// Minimal rows without rank and change
<HorizontalBarChart variant="simple" data={browsers} formatValue={(v) => v + '%'} />

Features

Built-in functionality

  • Rank indicators: The leading row gets the primary badge
  • Change arrows: Up/down indicators with color coding
  • Two variants: Ranked rows or compact label-above-bar rows
  • Hover states: Interactive opacity on hover
  • Responsive: Adapts to container width

Accessibility

Accessibility considerations

ARIA Attributes

Uses role="img" for chart containeraria-label describes chart contentValues included as text labels

Keyboard Navigation

KeyAction
N/AChart is not interactive by default

Notes

  • Rank and value are visible as text
  • Change direction communicated with arrows and color
  • Consider data table for complex datasets

Related Components