Skip to content
OTF Kit logoOTF Kit

Shadcn-style Bar Chart

Data

Shadcn-style bar chart for React. A bar graph from the Bar Chart component on Recharts, with one or more series, an optional stack, and a tooltip.

View in Storybook
Bar Chart
Loading Storybook preview…

Installation

bun add @otfdashkit/ui

Usage

Import Bar Chart from @otfdashkit/ui.

Code
// Bar Chart — Shadcn-style bar chart for React. A bar graph from the Bar Chart component on Recharts, with one or more series, an optional stack, and a tooltip.
//
// Install:
//   bun add @otfdashkit/ui

import { BarChart } from '@otfdashkit/ui'

export function Example() {
  return (
    <BarChart>
      {/* your content */}
    </BarChart>
  )
}

Props

Props declared in the BarChart source. Inherited HTML attributes are not listed.

PropTypeDefaultDescription
datarequiredRecord<string, unknown>[]
dataKeyrequiredstring | string[]
barCategoryGapstring | number'45%'Gap between bar groups. Defaults to '45%' for generous whitespace.
barSizenumber28Exact bar width/height in px. Defaults to 28 for a slim, elegant look.
classNamestring
colorsstring[]
heightnumber300
layout'vertical' | 'horizontal''horizontal'
lineColorstring'hsl(var(--foreground))'
lineDataKeystringOptional line overlay key — switches to ComposedChart with second Y axis
lineStrokeWidthnumber2
maxBarSizenumberMaximum bar width/height in px
rightAxisDomain[string | number, string | number]
rightAxisFormatter(v: number) => string
showGridbooleantrue
showLegendbooleanfalse
showTooltipbooleantrue
stackedbooleanfalse
xAxisKeystring'name'

Related

Questions

What is a bar chart used for?
It plots numeric series as bars. Pass data and dataKey. Set stacked to stack the series. Set layout to vertical to put the category on the Y axis. The tooltip and the grid are on unless you turn them off.
What is bar charts?
The Bar Chart component on this page. Each dataKey is one series. Recharts draws the bars. An optional lineDataKey adds a line on a second axis.
How to describe a bar chart?
Each row in data is a category. xAxisKey names that field and defaults to name. Each dataKey becomes a bar. The colors prop overrides the palette built into the component.
How to use a bar chart?
Import BarChart from @otfdashkit/ui and render it with data and dataKey. This page is the component, not a separate hosted chart creator. The preview is the Storybook story charts-areachart--bar-basic.
What is a barchart?
The same Bar Chart component. The function name is BarChart.