BarChart

A vertical bar chart for comparing values across categories, with optional stacking.

Installation

npx @obi/ui add bar-chart

Requires: recharts

Preview

Usage

import { BarChart } from '@/src/components/Charts/Charts';

const data = [
  { quarter: 'Q1', sales: 4000, returns: 400 },
  { quarter: 'Q2', sales: 3000, returns: 300 },
  { quarter: 'Q3', sales: 5000, returns: 200 },
  { quarter: 'Q4', sales: 4780, returns: 180 },
];

export default function Example() {
  return (
    <BarChart
      data={data}
      xKey="quarter"
      series={[
        { key: 'sales', label: 'Sales' },
        { key: 'returns', label: 'Returns' },
      ]}
    />
  );
}

Props

NameTypeDefaultDescription
dataChartDataPoint[]Array of data objects.
xKeystringKey to use as the x-axis label.
seriesChartSeries[]Bar groups to render.
stackedbooleanfalseStack series on top of each other.
heightnumber240Chart height in px.
showLegendbooleantrueWhether to show the legend.
showGridbooleantrueWhether to show the background grid.
classNamestring""Extra classes applied to the container.