> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bar

> Bar chart implementation for @servicetitan/anvil2-rn-charts-kit.

A bar chart shows distribution within a single series. Each bar is a variable, so `variant` assigns color per datum. Use `monochrome` for four or fewer ordered variables, and `categorical` for five or more.

* Design rules: [Bar charts](/docs/web/data-visualization/bar-charts)
* Shared API / tooltips / palettes: [Chart component](/docs/kits/charts-react-native/chart)

***

## Minimal option

Define structure and data in the option. The palette, corner radius, and hover behavior come from `variant`. Orientation follows the axis layout rather than a `Chart` prop: the `category` axis holds the labels and the `value` axis holds the measurements.

```tsx theme={null}
const option: EChartsOption = {
  grid: { left: 48, right: 16, top: 24, bottom: 32 },
  xAxis: { type: "category", data: ["North", "South", "East", "West"] },
  yAxis: { type: "value" },
  series: [{ type: "bar", data: [1200, 980, 1450, 1100] }],
};

<Chart
  option={option}
  variant="monochrome"
  width={480}
  height={300}
  accessibilityLabel="Bar chart. Sales by region."
/>;
```

***

## Variant styling

`variant` applies the following treatment:

| Concern       | Behavior                                             |
| ------------- | ---------------------------------------------------- |
| Color         | Monochrome steps or categorical hues by datum index  |
| Corner radius | Open end of each bar, following orientation and sign |
| Hover         | Series focus and blur                                |

Avoid hand-authoring `borderRadius` or palette hex values to reproduce this treatment.

***

## Direct labels

Direct labels keep values visible without a tooltip. Categorical bar charts require them, because the categorical hues do not all reach a 3:1 contrast ratio against each other.

The chart theme styles `bar.label` with a font, a translucent background, and 4px of padding, and leaves it at `show: false`. Enable it for the orientation in use:

* Vertical bars: `label: { show: true, position: "top" }` places the label above the open end
* Horizontal bars: `label: { show: true, position: "right" }` places the label past the open end

Leave `renderTooltip` unset when direct labels carry enough information. Widen `grid` on the open end so labels are not clipped.

```tsx theme={null}
// Horizontal — label at the end of each bar
const option: EChartsOption = {
  grid: { left: 96, right: 56, top: 24, bottom: 32 },
  xAxis: { type: "value" },
  yAxis: { type: "category", data: ["North", "South", "East", "West"] },
  series: [
    {
      type: "bar",
      data: [1200, 980, 1450, 1100],
      // Theme supplies font / background / padding; only show + position are required.
      label: { show: true, position: "right" },
    },
  ],
};

<Chart
  option={option}
  variant="monochrome"
  width={560}
  height={300}
  accessibilityLabel="Bar chart. Sales by region."
/>;

// Vertical bars use the same opt-in with position: "top" (and extra grid.top).
```

***

## Tooltips

Pass `renderTooltip` for richer content, either in place of direct labels or alongside them. See [Chart component](/docs/kits/charts-react-native/chart#tooltips).

```tsx theme={null}
import { Chart } from "@servicetitan/anvil2-rn-charts-kit";
import { TooltipSurface } from "@servicetitan/anvil2-rn";
import type { ChartTooltipInfo } from "@servicetitan/anvil2-rn-charts-kit";
import type { EChartsOption } from "@servicetitan/anvil2-rn-charts-kit";
import { Text, View } from "react-native";

function renderTooltip({ name, points }: ChartTooltipInfo) {
  return (
    <TooltipSurface
      accessibilityLabel={name}
      content={
        <View>
          <Text>{name}</Text>
          {points.map((point) => (
            <Text key={point.seriesIndex}>
              {point.seriesName ? `${point.seriesName}: ` : ""}
              {String(point.value)}
            </Text>
          ))}
        </View>
      }
    />
  );
}

const option: EChartsOption = {
  grid: { left: 48, right: 16, top: 24, bottom: 32 },
  xAxis: { type: "category", data: ["North", "South", "East", "West"] },
  yAxis: { type: "value" },
  series: [{ type: "bar", data: [1200, 980, 1450, 1100] }],
};

<Chart
  option={option}
  variant="monochrome"
  renderTooltip={renderTooltip}
  width={480}
  height={300}
  accessibilityLabel="Bar chart. Sales by region."
/>;
```
