Skip to Content
文档

条形列表

用于使用水平条显示分类数据,显示不同类别或项目之间的比较

Storybook
ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo
1.35M
1.2M
200K
100K
100K
100K
20K

用法

¥Usage

import { BarList, Chart, useChart } from "@chakra-ui/charts"
<BarList.Root>
  <BarList.Content>
    <BarList.Bar />
    <BarList.Value />
  </BarList.Content>
</BarList.Root>

示例

¥Examples

排序顺序

¥Sort Order

sort 键设置为 { by: "value", direction: "asc" },以便按升序对柱状图进行排序。

¥Set the sort key to { by: "value", direction: "asc" } to sort the bars in ascending order.

const chart = useChart<BarListData>({
  sort: { by: "value", direction: "asc" },
  // ...
})
Yahoo
Direct
Github
Yandex
Bing
Google
ChatGPT
20K
100K
100K
100K
200K
1.2M
1.35M

格式值

¥Format Value

valueFormatter 属性传递给 BarList.Value 组件,以格式化条形的值。

¥Pass the valueFormatter prop to the BarList.Value component to format the value of the bars.

<BarList.Value valueFormatter={(value) => value.toLocaleString()} />
Created
Initial Contact
Booked Demo
Closed
120 (45%)
90 (34%)
45 (17%)
10 (4%)

标签

¥Labels

要向柱状图添加名称和值标签,请使用 BarList.Label 组件。

¥To add name and value labels to the bars, use the BarList.Label component.

<BarList.Label title="Search Engine" flex="1">
  <BarList.Bar />
</BarList.Label>

Search Engine

ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo

Downloads

1.35M
1.2M
200K
100K
100K
100K
20K

链接

¥Link

要使栏渲染链接,请将 label 属性传递给 BarList.Bar 组件。

¥To make the bars render a link, pass the label prop to the BarList.Bar component.

<BarList.Bar
  label={({ payload }) => <a href={payload.href}>{payload.name}</a>}
/>

工具提示

¥Tooltip

tooltip 属性传递给 BarList.Bar 组件,以在鼠标悬停在柱状图上时显示工具提示。

¥Pass the tooltip prop to the BarList.Bar component to show a tooltip when hovering over the bar.

Search Engine

ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo

Downloads

1.35M
1.2M
200K
100K
100K
100K
20K

多个值

¥Multiple values

以下是如何渲染条形的值和百分比的示例。

¥Here's an example of how to render the value and percent of the bars.

Search Engine

ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo

Downloads

1.35M
1.2M
200K
100K
100K
100K
20K

%

43.88%
39.15%
6.53%
3.26%
3.26%
3.26%
0.65%

Previous

柱状图

Next

条形片段