# BulletChart
Package: @mantine/charts
Import: import { BulletChart } from '@mantine/charts';
Description: Compact KPI chart with value, target, and qualitative ranges

## Usage

`BulletChart` displays a value against a target on top of range bands:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      target={150000}
      ranges={ranges}
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Data format

Each item in `ranges` sets the upper bound of a band with `value` and its `color`.
The optional `label` names the band. It is read by screen readers and shown in the default tooltip.
Visible labels always show the formatted range value.

```tsx
const ranges = [
  { value: 100000, color: 'red.8', label: 'Poor' },
  { value: 200000, color: 'yellow.8', label: 'Average' },
  { value: 300000, color: 'teal.8', label: 'Good' },
];
```

The scale ends at the largest of the ranges, `value` and `target`.
A value beyond all ranges extends the scale, and `NaN` or `Infinity` values are not displayed.

## Label

Use `label` prop to display a label next to the chart:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      target={150000}
      ranges={ranges}
      label="Revenue"
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Vertical orientation

Set `orientation="vertical"` to render the chart vertically. Vertical chart requires a fixed height:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      target={150000}
      ranges={ranges}
      orientation="vertical"
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
      h={250}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Bar color

Use `barColor` prop to change the value bar color and `targetColor` to change the target marker color:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      target={150000}
      ranges={ranges}
      barColor="black"
      targetColor="white"
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Chart size

Use `size` prop to change the thickness of the track and `barSize` to change the thickness of the value bar:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { Stack } from '@mantine/core';
import { ranges } from './data';

function Demo() {
  return (
    <Stack>
      <BulletChart
        value={230000}
        target={150000}
        ranges={ranges}
        size={20}
        barSize={10}
        label="Small"
        valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
      />
      <BulletChart
        value={230000}
        target={150000}
        ranges={ranges}
        size={32}
        barSize={16}
        label="Default"
        valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
      />
      <BulletChart
        value={230000}
        target={150000}
        ranges={ranges}
        size={48}
        barSize={24}
        label="Large"
        valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
      />
    </Stack>
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Value formatter

Use `valueFormatter` prop to format values in labels and tooltip. Set `withTooltip` to display the tooltip on hover and keyboard focus:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      target={150000}
      ranges={ranges}
      withTooltip
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Without target

The target marker is rendered only when the `target` prop is set:

```tsx
// Demo.tsx
import { BulletChart } from '@mantine/charts';
import { ranges } from './data';

function Demo() {
  return (
    <BulletChart
      value={230000}
      ranges={ranges}
      valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
    />
  );
}

// data.ts
export const ranges = ${JSON.stringify(ranges, null, 2)};
```


## Accessibility

Set `aria-label` to translate the chart summary or describe the value relative to its target:

```tsx
<BulletChart aria-label="Ingresos: 230k, objetivo 150k" value={230000} target={150000} ranges={ranges} />
```


#### Props

**BulletChart props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| barColor | MantineColor | 'white' | Color of the actual value bar |
| barSize | string \| number | 16 | Thickness of the actual value bar |
| getTooltipLabel | ((data: { value: number; target?: number; }) => ReactNode) \| undefined | - | Custom tooltip content, called only when `withTooltip` is set. `value` is passed as is, a non-finite `target` is passed as `undefined` |
| label | React.ReactNode | - | Label displayed next to the chart |
| orientation | "horizontal" \| "vertical" | 'horizontal' | Orientation |
| ranges | BulletChartRange[] | required | Qualitative ranges displayed as background bands |
| size | string \| number | 32 | Thickness of the chart track area (ranges) |
| target | number | - | Target value, displayed as a marker line |
| targetColor | MantineColor | 'black' | Color of the target marker |
| targetRatio | number | 0.7 | Target marker length relative to the track thickness |
| targetSize | string \| number | 2 | Target marker thickness |
| value | number | required | Current actual value |
| valueFormatter | (value: number) => string | - | Value formatter for tooltip/display and labels |
| withTooltip | boolean | false | If set, the chart displays a tooltip on hover and becomes focusable to display it on focus |


#### Styles API

BulletChart component supports Styles API. With Styles API, you can customize styles of any inner element. Follow the documentation to learn how to use CSS modules, CSS variables and inline styles to get full control over component styles.

**BulletChart selectors**

| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-BulletChart-root | Root element |
| label | .mantine-BulletChart-label | Label element |
| trackWrapper | .mantine-BulletChart-trackWrapper | Wrapper around track and value labels |
| track | .mantine-BulletChart-track | Container for ranges, bar, and target |
| range | .mantine-BulletChart-range | Background range band |
| bar | .mantine-BulletChart-bar | Actual value bar |
| target | .mantine-BulletChart-target | Target marker line |
| rangeLabel | .mantine-BulletChart-rangeLabel | Formatted range value at the end of each range (range.label is not displayed) |
| barLabel | .mantine-BulletChart-barLabel | Value label for the actual value bar |
| targetLabel | .mantine-BulletChart-targetLabel | Value label for the target marker |

**BulletChart CSS variables**

| Selector | Variable | Description |
|----------|----------|-------------|
| root | --bullet-size | Controls thickness of the chart track area |
| root | --bullet-bar-size | Controls thickness of the actual value bar |

**BulletChart data attributes**

| Selector | Attribute | Condition | Value |
|----------|-----------|-----------|-------|
| root | data-orientation | `orientation` prop value | - |
| trackWrapper | data-with-target | `target` is a finite number | - |
