Moul UIBeta
ComponentsCharts

BarChart

Documentation for the BarChart component.

BarChart

A highly configurable bar chart supporting vertical layouts, horizontal layouts, stacking, and custom category-based coloring.

Preview

Vertical Bar Chart (Categorical)

United States7.53k
Netherlands4.67k
Singapore1.4k
Canada1.37k
Ireland271
India270

Horizontal Bar Chart (Categorical)

United States7.53k
Netherlands4.67k
Singapore1.4k
Canada1.37k
Ireland271
India270

Stacked Bar Chart

Import

import { BarChart, ChartContainer } from '@moul-dev/ui';

Usage

Categorical Bar Chart

Color each bar individually based on its row index (useful for single series):

import { BarChart, ChartContainer } from '@moul-dev/ui';

export default function Example() {
  const data = [
    { country: 'United States', Requests: 7530 },
    { country: 'Netherlands', Requests: 4670 },
    { country: 'Singapore', Requests: 1400 },
  ];

  return (
    <ChartContainer title="All requests">
      <BarChart
        data={data}
        indexKey="country"
        categories={['Requests']}
        categorical
        height={300}
      />
    </ChartContainer>
  );
}

Props

BarChart Props

PropTypeDefaultDescription
dataany[]Array of data objects.
indexKeystringKey representing the categories.
categoriesstring[]Series dataKeys.
colorsstring[]CHART_COLORSColor palette for bars.
layout'horizontal' | 'vertical''horizontal'Orientation layout.
stackedbooleanfalseEnable stacked bars.
categoricalbooleanfalseColor each bar individually based on index.
valueFormatter(value: any) => stringCustom formatter for values.
heightnumber | string300Height of the chart.
gridLinesbooleantrueShow horizontal/vertical grid lines.

On this page