AreaChart
Area chart component with stacked, percent and split variants
Source
Docs
Package
Usage
Use AreaChart component without type prop to render a regular area chart.
In a regular area chart, each data series is plotted on its own and does
not interact with other series.
Stacked area chart
Set type="stacked" to render a stacked area chart. In this type of area chart
stacking is applied along the vertical axis, allowing you to see the overall trend
as well as the contribution of each individual series to the total.
Percent area chart
Set type="percent" to render a percent area chart. In this type of area chart
the y-axis scale is always normalized to 100%, making it easier to compare the
contribution of each series in terms of percentages.
Split area chart
Set type="split" to render a split area chart. In this type of area chart
fill color is split into two colors, one for positive values and one for negative
values. Split area chart supports only one data series.
Split colors
Set splitColors prop to an array of two colors to customize the fill color of
split area chart. The first color is used for positive values and the second color
for negative values. splitColors prop is ignored in other types of area charts.
Legend
To display chart legend, set withLegend prop. When one of the items in the legend
is hovered, the corresponding data series is highlighted in the chart.
Legend position
You can pass props down to recharts Legend
component with legendProps prop. For example, setting legendProps={{ verticalAlign: 'bottom', height: 50 }}
will render the legend at the bottom of the chart and set its height to 50px.
Series labels
By default, series name is used as a label. To change it, set label
property in series object:
Connect nulls
Use connectNulls prop to specify whether to connect a data point across null
points. By default, connectNulls is true.
Points labels
To display labels on data points, set withPointLabels:
X and Y axis props
Use xAxisProps and yAxisProps to pass props down to recharts XAxis
and YAxis components. For example, these props
can be used to change orientation of axis:
Axis labels
Use xAxisLabel and yAxisLabel props to display axis labels:
X axis offset
Use xAxisProps to set padding between the charts ends and the x-axis:
Y axis scale
Use yAxisProps to change domain of the Y axis. For example, if you know that
your data will always be in the range of 0 to 100, you can set domain to [0, 100]:
Right Y axis
To display additional Y axis on the right side of the chart, set withRightYAxis prop.
You can pass props down to recharts YAxis
component with rightYAxisProps prop and assign a label to the right Y axis with
rightYAxisLabel prop. Note that you need to bind data series to the right Y axis
by setting yAxisId in the series object.
Rotate x-axis labels
To rotate x-axis labels, set xAxisProps.angle to a number of degrees to rotate:
Value formatter
To format values in the tooltip and axis ticks, use valueFormat prop. It accepts
a function that takes number value as an argument and returns formatted value:
Area color
You can reference colors from theme the same way as in
other components, for example, blue, red.5, orange.7, etc. Any valid CSS
color value is also accepted.
Change area color depending on color scheme
You can use CSS variables in color property. To define a CSS variable that
changes depending on the color scheme, use light/dark mixins
or light-dark function. Example
of area that is dark orange in light mode and lime in dark mode:
Stroke dash array
Set strokeDasharray prop to control the stroke dash array of the grid and cursor
lines. The value represent the lengths of alternating dashes and gaps. For example,
strokeDasharray="10 5" will render a dashed line with 10px dashes and 5px gaps.
Grid and text colors
Use --chart-grid-color and --chart-text-color to change colors of
grid lines and text within the chart. With CSS modules, you can change colors
depending on color scheme:
If your application has only one color scheme, you can use gridColor and textColor
props instead of CSS variables:
Tooltip animation
By default, tooltip animation is disabled. To enable it, set tooltipAnimationDuration
prop to a number of milliseconds to animate the tooltip position change.
Units
Set unit prop to render a unit label next to the y-axis ticks and tooltip values:
Custom tooltip
Use tooltipProps.content to pass custom tooltip renderer to recharts Tooltip
component. Note that it is required to filter recharts payload with getFilteredChartTooltipPayload
function to remove empty values that are used for styling purposes only.
Remove tooltip
To remove tooltip, set withTooltip={false}. It also removes the cursor line
and disables interactions with the chart.
Customize dots
Use dotProps to pass props down to recharts dot in regular state and activeDotProps
to pass props down to recharts dot in active state (when cursor is over the current series).
Stroke width
Use strokeWidth prop to control the stroke width of all areas:
Fill opacity
Use fillOpacity prop to control the fill opacity of all areas:
Sync multiple AreaCharts
You can pass props down to recharts AreaChart
component with areaChartProps prop. For example, setting areaChartProps={{ syncId: 'any-id' }}
will sync tooltip of multiple AreaChart components with the same syncId prop.
Apples sales:
Tomatoes sales:
Vertical orientation
Set orientation="vertical" to render a vertical area chart:
Dashed area line
Set strokeDasharray property in series to change line style to dashed:
Reference lines
Use referenceLines prop to render reference lines. Reference lines are always
rendered behind the chart.