shadcn.io is not affiliated with official shadcn/ui
Chart examples · Area
An area chart with axes for React
A stacked area chart with a Y axis showing three value ticks.
Use it when readers need to read values off the chart. A YAxis with three ticks gives the scale next to the stacked desktop and mobile areas.
Preview
Installation
FAQ
How many numbers does the Y axis show?
YAxis sets tickCount={3}, so Recharts aims for three ticks. axisLine and tickLine are false, and tickMargin is 8. This file doesn't set tickFormatter on YAxis, so the ticks are the raw scale numbers.
Why is the left margin negative?
AreaChart sets margin to left: -20 and right: 12. The negative left margin pulls the plot toward the frame so the YAxis labels sit in that gutter. The right margin is 12, matching the other edge's padding on the X ticks.
How do desktop and mobile stack?
Both Area components set stackId="a". Mobile is first, on the baseline. Desktop is second, on top of it. Both use type="natural" and fillOpacity={0.4}, with fill and stroke of var(--color-mobile) and var(--color-desktop).
How are the month ticks shortened?
XAxis uses dataKey="month" and tickFormatter={formatMonth}, which returns value.slice(0, 3). axisLine and tickLine are false, and tickMargin is 8. CartesianGrid sets vertical={false}, so the grid lines run across the Y scale.
Related
- A simple area chartA single-series area chart with a smooth
- A stacked area chartAn area chart stacking desktop and mobile
- A bar chartA bar chart with rounded corners
- A line chartA line chart drawing one series as a
- An area chart with gradient fillA stacked area chart whose areas fade
- An area chart with a legendA stacked area chart of desktop and