Skip to Content
文档

面积图

用于通过填充线和轴之间的区域来显示定量数据,显示随时间变化的趋势和模式。

StorybookRecharts

用法

¥Usage

import { Chart, useChart } from "@chakra-ui/charts"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"
<Chart.Root>
  <AreaChart>
    <CartesianGrid />
    <XAxis />
    <YAxis />
  </AreaChart>
</Chart.Root>

示例

¥Examples

值轴

¥Value Axis

使用 recharts 中的 YAxis 组件显示 y 轴。

¥Use the YAxis component from recharts to display the y-axis.

虚线区域

¥Dashed Area

strokeDasharray 属性设置为你想要显示为虚线的 series

¥Set the strokeDasharray prop to the series you want to display as a dashed line.

渐变区域

¥Gradient Area

使用 Chart.Gradient 组件为该区域创建渐变填充。

¥Use the Chart.Gradient component to create a gradient fill for the area.

注意:渐变的 id 必须是唯一的,并在 Area 组件的 fill 属性中引用。

填充内容值

¥Fill With Value

使用 Chart.Gradient 组件创建渐变填充,根据值从一种颜色变为另一种颜色。

¥Use the Chart.Gradient component to create a gradient fill that changes from one color to another based on the value.

<defs>
  <Chart.Gradient
    id="uv-gradient"
    stops={[
      { offset: "0%", color: "teal.solid", opacity: 1 },
      { offset: "100%", color: "red.solid", opacity: 1 },
    ]}
  />
</defs>

当值为正时,使用第一种颜色;当值为负时,使用第二种颜色。

¥When the value is positive, it uses the first color, and when negative, it uses the second color.

百分比

¥Percent

要将面积图渲染为百分比,并将值标准化为 100%:

¥To render the area chart as a percentage, with value normalized to 100%:

  • Area 组件上的 stackId 属性设置为相同的值。

  • AreaChart 组件上将 stackOffset 属性设置为 expand

  • 通过 tickFormatter 属性将 y 轴格式化为百分比格式

¥Dots

Area 组件上设置 dot 属性以显示映射到每个数据点的点。

¥Set the dot prop on the Area component to display dots that map to each data point.

<Area dot={{ fill: "red", fillOpacity: 1 }} activeDot={false} />

连接空值

¥Connect Nulls

connectNulls 属性传递给 Area 组件,即可连接数据点,即使中间有 null 个值。当你想在缺少数据点的情况下显示连续的线条时,这很有用。

¥Pass the connectNulls prop to the Area component to connect data points even when there are null values in between. This is useful when you want to show a continuous line despite missing data points.

<Area connectNulls={false} />

<Area connectNulls={true} />

参考线

¥Reference Line

使用 recharts 中的 ReferenceLine 组件为图表添加参考线。当你想高亮图表中的特定值时,参考线非常有用。

¥Use the ReferenceLine component from recharts to add a reference line to your chart. A reference line is useful when you want to highlight a specific value in the chart.

参考区域

¥Reference Area

使用 recharts 中的 ReferenceArea 组件为图表添加参考区域。当你想高亮图表中的特定范围时,参考区域非常有用。

¥Use the ReferenceArea component from recharts to add a reference area to your chart. A reference area is useful when you want to highlight a specific range in the chart.

面积类型

¥Area Types

Recharts 为各种面积图提供灵活的支持。

¥Recharts provides flexible support for various kinds of area charts.

以下是你可以创建的不同类型的面积图:

¥Below are the different types of area charts you can create:

<Area type="linear" />

<Area type="bump" />

<Area type="basis" />

<Area type="step" />

<Area type="stepBefore" />

<Area type="stepAfter" />

<Area type="natural" />

<Area type="monotone" />

Previous

笛卡尔网格

Next

柱状图