apps/www/content/docs/charts/area-chart.mdx
import { Chart, useChart } from "@chakra-ui/charts"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"
<Chart.Root>
<AreaChart>
<CartesianGrid />
<XAxis />
<YAxis />
</AreaChart>
</Chart.Root>
Use the YAxis component from recharts to display the y-axis.
Set the strokeDasharray prop to the series you want to display as a dashed
line.
Use the Chart.Gradient component to create a gradient fill for the area.
<ExampleTabs name="charts/area-chart-with-gradient" />Note: The
idof the gradient must be unique and referenced in thefillprop of theAreacomponent.
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.
<ExampleTabs name="charts/area-chart-fill-with-value" />To render the area chart as a percentage, with value normalized to 100%:
stackId prop on the Area component to the same valuestackOffset prop to expand on the AreaChart componenttickFormatter prop to percentage formatSet the dot prop on the Area component to display dots that map to each data
point.
<Area dot={{ fill: "red", fillOpacity: 1 }} activeDot={false} />
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.
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.
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.
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>