File size: 3,311 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
---
title: Area Chart
description:
Used to display quantitative data by filling the area between the line and
axis, showing trends and patterns over time
links:
storybook: charts-area-chart--basic
recharts: https://recharts.org/en-US/api/AreaChart
---
<ExampleTabs name="charts/area-chart-basic" />
## Usage
```tsx
import { Chart, useChart } from "@chakra-ui/charts"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"
```
```tsx
<Chart.Root>
<AreaChart>
<CartesianGrid />
<XAxis />
<YAxis />
</AreaChart>
</Chart.Root>
```
## Examples
### Value Axis
Use the `YAxis` component from `recharts` to display the y-axis.
<ExampleTabs name="charts/area-chart-with-value-axis" />
### Dashed Area
Set the `strokeDasharray` prop to the `series` you want to display as a dashed
line.
<ExampleTabs name="charts/area-chart-with-dashed-area" />
### Gradient Area
Use the `Chart.Gradient` component to create a gradient fill for the area.
> **Note:** The `id` of the gradient must be unique and referenced in the `fill`
> prop of the `Area` component.
<ExampleTabs name="charts/area-chart-with-gradient" />
### Fill With Value
Use the `Chart.Gradient` component to create a gradient fill that changes from
one color to another based on the value.
```tsx {4-7}
<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.
<ExampleTabs name="charts/area-chart-fill-with-value" />
### Percent
To render the area chart as a percentage, with value normalized to 100%:
- Set the `stackId` prop on the `Area` component to the same value
- Set the `stackOffset` prop to `expand` on the `AreaChart` component
- Format the y-axis via the `tickFormatter` prop to percentage format
<ExampleTabs name="charts/area-chart-percent" />
### Dots
Set the `dot` prop on the `Area` component to display dots that map to each data
point.
```tsx
<Area dot={{ fill: "red", fillOpacity: 1 }} activeDot={false} />
```
<ExampleTabs name="charts/area-chart-with-dots" />
### Connect Nulls
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.
<ExampleTabs name="charts/area-chart-with-nulls" />
### Reference Line
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.
<ExampleTabs name="charts/area-chart-with-reference-lines" />
### Reference Area
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.
<ExampleTabs name="charts/area-chart-with-reference-area" />
### Area Types
Recharts provides flexible support for various kinds of area charts.
Below are the different types of area charts you can create:
<Box mt="12" borderWidth="1px" ps="3" pe="10" py="10" rounded="l2">
<ExamplePreview name="charts/area-chart-with-types" />
</Box>
|