Join our Discord community
Bar chart

Dual-Labeled Horizontal Chart

Horizontal bar chart component with custom inside and outside labels. Built for React applications requiring detailed horizontal data visualization with Next.js and TypeScript.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/bar-chart-07.json
npx shadcn@latest add https://www.shadcn.io/registry/bar-chart-07.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/bar-chart-07.json
bunx shadcn@latest add https://www.shadcn.io/registry/bar-chart-07.json

Features

  • Dual label system with inside category labels and outside value labels
  • Horizontal layout optimized for category names and data display
  • Custom label positioning using insideLeft and right positioning
  • Hidden axes focusing attention on data and labels rather than scales
  • TypeScript support with complete type definitions for custom labeled charts
  • shadcn/ui integration using Chart components with advanced label styling

Use Cases

This free open source React component works well for:

  • Category rankings - Applications showing named categories with values built with Next.js
  • Space-efficient displays - Horizontal layouts for long category names using TypeScript and Tailwind CSS
  • Comparative analysis - Charts where both category and value identification is crucial
  • Dashboard widgets - Compact horizontal visualizations with comprehensive labeling

API Reference

ChartBarLabelCustom

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the container

Dual Label Configuration

Two LabelList components for comprehensive labeling:

<Bar dataKey="desktop" layout="vertical" fill="var(--color-desktop)" radius={4}>
  <LabelList
    dataKey="month"
    position="insideLeft"
    offset={8}
    className="fill-(--color-label)"
    fontSize={12}
  />
  <LabelList
    dataKey="desktop"
    position="right"
    offset={8}
    className="fill-foreground"
    fontSize={12}
  />
</Bar>

Layout Configuration

Horizontal bar chart with hidden axes:

<BarChart
  accessibilityLayer
  data={chartData}
  layout="vertical"
  margin={{ right: 16 }}
>
  <YAxis dataKey="month" type="category" hide />
  <XAxis dataKey="desktop" type="number" hide />
</BarChart>

Label Properties

  • Inside Label: Category names positioned insideLeft with label color
  • Outside Label: Data values positioned right with foreground color
  • Offset: 8px spacing for both label types
  • Font Size: 12px for optimal readability

Implementation Notes

  • Vertical layout enables horizontal bar orientation
  • Both Y-axis and X-axis are hidden to focus on labels
  • Right margin (16px) provides space for outside value labels
  • Inside labels use background color for contrast against bar color
  • Outside labels use foreground color for clear value reading
  • Perfect for applications requiring both category identification and precise value display in horizontal format