Bar Chart

v0.2.2

Fully presentational bar chart widget using Recharts. Supports multiple bars, stacked bars, horizontal/vertical layouts, custom styling, and responsive design.

View as Markdown

Install

npx shadcn@latest add @signalos/bar-chart

Requires a configured @signalos registry and a valid SIGNALOS_REGISTRY_TOKEN - get access. Registry dependencies (@signalos/tokens, @signalos/chart-core) are pulled automatically.

Preview

Example & code

bar-chart.example.tsx
import { BarChart } from "@/components/widgets/bar-chart/BarChart"

const data = [
  { product: "Product A", sales: 4000, returns: 400 },
  { product: "Product B", sales: 3000, returns: 300 },
  { product: "Product C", sales: 2000, returns: 200 },
  { product: "Product D", sales: 2780, returns: 278 },
  { product: "Product E", sales: 1890, returns: 189 },
]

export default function BarChartExample() {
  return (
    <BarChart
      data={data}
      bars={[
        { dataKey: "sales", name: "Sales", fill: "var(--chart-1)" },
        { dataKey: "returns", name: "Returns", fill: "var(--chart-2)" },
      ]}
      xAxis={{ dataKey: "product" }}
      yAxis={{ tickFormatter: (value) => `$${value}` }}
      height={350}
    />
  )
}

Props

BarChartDataPoint

PropTypeDefaultDescription

BarChartBar

PropTypeDefaultDescription
dataKey*string-The data key to plot from your data points
namestring | undefined-Display name for the legend and tooltip
fillstring | undefined-Bar fill color (use CSS custom property or hex)
strokestring | undefined-Bar stroke color
strokeWidthnumber | undefined-Bar stroke width
stackIdstring | undefined-Stack ID for stacked bars (bars with same stackId will stack)
radiusnumber | [number, number, number, number] | undefined-Radius for bar corners [topLeft, topRight, bottomRight, bottomLeft]
animationDurationnumber | undefined-Whether to animate the bar on mount

BarChartAxis

PropTypeDefaultDescription
dataKeystring | undefined-The data key for this axis
axisLineboolean | undefined-Whether to show the axis line
tickLineboolean | undefined-Whether to show tick marks
tickFormatter((value: unknown) => string) | undefined-Custom tick formatter function
labelstring | { value: string; angle?: number | undefined; position?: string | undefined; } | undefined-Label for the axis
hideboolean | undefined-Whether to hide the axis entirely
tickboolean | object | undefined-Axis tick styles

BarChartGrid

PropTypeDefaultDescription
horizontalboolean | undefined-Show horizontal grid lines
verticalboolean | undefined-Show vertical grid lines
strokestring | undefined-Grid line stroke color
strokeDasharraystring | undefined-Grid line stroke dash pattern

BarChartLegend

PropTypeDefaultDescription
verticalAlign"bottom" | "top" | "middle" | undefined-Legend position
align"left" | "center" | "right" | undefined-
layout"horizontal" | "vertical" | undefined-Legend layout
iconType"line" | "plainline" | "square" | "rect" | "circle" | "cross" | "diamond" | "star" | "triangle" | "wye" | undefined-Custom icon type
formatter((value: string) => ReactNode) | undefined-Custom legend formatter

BarChartTooltip

PropTypeDefaultDescription
labelFormatter((label: unknown) => ReactNode) | undefined-Custom tooltip formatter for label
formatter((value: ValueType, name: NameType, entry: Payload<ValueType, NameType>) => ReactNode) | undefined-Custom tooltip formatter for values
cursorboolean | object | undefined-Cursor style

BarChartProps

PropTypeDefaultDescription
data*BarChartDataPoint[]-Array of data points to plot
bars*BarChartBar[]-Array of bar configurations
widthnumber | undefined-Chart width in pixels
heightnumber | undefined-Chart height in pixels
layout"horizontal" | "vertical" | undefined-Bar layout: "horizontal" = standard upright bars (default), "vertical" = sideways bars
xAxisBarChartAxis | undefined-X-axis configuration
yAxisBarChartAxis | undefined-Y-axis configuration
gridboolean | BarChartGrid | undefined-Grid configuration
legendboolean | BarChartLegend | undefined-Legend configuration (false to hide)
tooltipboolean | BarChartTooltip | undefined-Tooltip configuration (false to hide)
margin{ top?: number | undefined; right?: number | undefined; bottom?: number | undefined; left?: number | undefined; } | undefined-Chart margin (top, right, bottom, left)
isLoadingboolean | undefined-Loading state
emptyStateReactNode-Empty state content
onBarClick((data: unknown, index: number) => void) | undefined-Click handler for bar data points
responsiveboolean | undefined-Responsive container (auto-sizes to parent)
classNamestring | undefined-Container className
styleCSSProperties | undefined-Custom container styles

npm dependencies

recharts@^2.15.0

Changelog

Changelog - BarChart

0.2.2

  • Fix onBarClick's index argument always being 0 regardless of which bar was clicked. Now derived from Recharts' activeTooltipIndex via chart-core's resolveChartClickIndex.

0.2.1

  • Update data-testid call sites for the renamed prop.

0.2.0

  • Factor shared colors, tooltip/legend config, skeleton, and empty state into the chart-core widget; public API unchanged.

0.1.1

  • Fixed axis type/dataKey mapping — layout="horizontal" now correctly renders category X-axis and numeric Y-axis (was inverted).
  • Changed default layout from "vertical" to "horizontal" (standard upright bars).
  • Stacked bars (stackId set) now default to radius={0} to avoid gaps between segments.
  • Replaced any types with proper Recharts types (ValueType, NameType, Payload) in BarChartTooltip.formatter, labelFormatter, tickFormatter, and onBarClick.

0.1.0

Initial release.

  • Bar chart component with Recharts integration
  • Support for multiple bars with custom colors and styling
  • Stacked bars support via stackId
  • Horizontal and vertical layouts
  • Configurable axes, grid, legend, and tooltip
  • Custom bar radius for rounded corners
  • Responsive container support
  • Loading skeleton and empty state
  • Fully presentational (props-in/events-out pattern)