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
1
Marketing Strategy
4,200
↑ 12%
2
Content Pipeline
3,100
↑ 8%
3
Product Launch
2,800
↓ 3%
4
Team Operations
2,400
↑ 15%
5
Research & Planning
1,900
↑ 5%
Simple Variant
Minimal horizontal bars without ranks
Chrome65%
Safari20%
Firefox10%
Other5%
Props
Component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
data* | { label: string; value: number; change?: number }[] | — | Array of bar data |
showRank | boolean | true (ranked) | Show rank badges |
showChange | boolean | true (ranked) | Show change indicators |
variant | 'ranked' | 'simple' | 'ranked' | Ranked rows or label-above-bar rows |
max | number | — | Scale bars against this value instead of the largest |
barHeight | number | 32 | Bar height in pixels |
formatValue | (v: number) => string | — | Value formatter function |
className | string | — | 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 labelsKeyboard Navigation
| Key | Action |
|---|---|
| N/A | Chart 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