Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Charts

Bar Segment

A part-to-whole bar with optional labels, values, legend and a reference marker.

BarSegment splits a single bar into colored segments. Each datum needs a name, value and color.

Usage

import { BarSegment, useChart } from '@saas-ui/charts'
const chart = useChart({
  data: [
    { name: 'Starter', value: 70, color: 'indigo.solid' },
    { name: 'Pro', value: 40, color: 'pink.solid' },
    { name: 'Enterprise', value: 25, color: 'fg' },
  ],
})

<BarSegment.Root chart={chart}>
  <BarSegment.Content>
    <BarSegment.Bar tooltip />
  </BarSegment.Content>
</BarSegment.Root>

Anatomy

<BarSegment.Root chart={chart}>
  <BarSegment.Content>
    <BarSegment.Label />
    <BarSegment.Bar tooltip>
      <BarSegment.Reference value={80} label="Limit" />
    </BarSegment.Bar>
    <BarSegment.Value />
  </BarSegment.Content>
  <BarSegment.Legend showValue showPercent />
</BarSegment.Root>

Segment width is the value's share of the total. BarSegment.Label and BarSegment.Value use the same flex basis so they line up with the bar.

Legend

BarSegment.Legend lists each segment with a swatch. Set showValue and showPercent to print the number and share.

Starter
Pro
Enterprise
70
40
25

Starter

7052%

Pro

4030%

Enterprise

2519%

Reference

BarSegment.Reference draws a marker at an absolute value on the same scale, useful for a quota or limit.

Limit

Used

7272%

Available

2828%

Previous

Bar List

Next

Overview