File size: 1,832 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
---
title: Bar List
description:
Used to display categorical data with horizontal bars, showing comparisons
between different categories or items
links:
storybook: charts-bar-list--basic
---
<ExampleTabs name="charts/bar-list-basic" />
## Usage
```tsx
import { BarList, Chart, useChart } from "@chakra-ui/charts"
```
```tsx
<BarList.Root>
<BarList.Content>
<BarList.Bar />
<BarList.Value />
</BarList.Content>
</BarList.Root>
```
## Examples
### Sort Order
Set the `sort` key to `{ by: "value", direction: "asc" }` to sort the bars in
ascending order.
```ts
const chart = useChart<BarListData>({
sort: { by: "value", direction: "asc" },
// ...
})
```
<ExampleTabs name="charts/bar-list-ascending" />
### Format Value
Pass the `valueFormatter` prop to the `BarList.Value` component to format the
value of the bars.
```tsx /valueFormatter={(value) => value.toLocaleString()}/
<BarList.Value valueFormatter={(value) => value.toLocaleString()} />
```
<ExampleTabs name="charts/bar-list-with-formatter" />
### Labels
To add name and value labels to the bars, use the `BarList.Label` component.
```tsx
<BarList.Label title="Search Engine" flex="1">
<BarList.Bar />
</BarList.Label>
```
<ExampleTabs name="charts/bar-list-with-label" />
### Link
To make the bars render a link, pass the `label` prop to the `BarList.Bar`
component.
```tsx
<BarList.Bar
label={({ payload }) => <a href={payload.href}>{payload.name}</a>}
/>
```
<ExampleTabs name="charts/bar-list-with-link" />
### Tooltip
Pass the `tooltip` prop to the `BarList.Bar` component to show a tooltip when
hovering over the bar.
<ExampleTabs name="charts/bar-list-with-tooltip" />
### Multiple values
Here's an example of how to render the value and percent of the bars.
<ExampleTabs name="charts/bar-list-with-multi-value" />
|