使用高级 Chakra UI 组件更快地构建 💎

了解更多
跳到内容
文档演练场指南博客
赞助商

条形列表

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

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

用法

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

示例

排序顺序

sort 键设置为 { by: "value", direction: "asc" } 可按升序排列条形图。

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

格式化值

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

<BarList.Value valueFormatter={(value) => value.toLocaleString()} />
已创建
首次联系
已预订演示
已关闭
120 (45%)
90 (34%)
45 (17%)
10 (4%)

标签

要为条形图添加名称和值标签,请使用 BarList.Label 组件。

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

搜索引擎

ChatGPT
Google
Bing
直接
Github
Yandex
Yahoo

下载量

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

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

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

工具提示

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

搜索引擎

ChatGPT
Google
Bing
直接
Github
Yandex
Yahoo

下载量

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

多个值

这是一个如何渲染条形图的值和百分比的示例。

搜索引擎

ChatGPT
Google
Bing
直接
Github
Yandex
Yahoo

下载量

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

%

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

上一个

条形图

下一个

条形分段