shadcn.io is not affiliated with official shadcn/ui
Chart examples · Line
A linear line chart for React
A line chart joining its monthly values with straight segments.
Use straight segments when the line should go exactly through each value without smoothing. type="linear" joins the six months point to point, so every change of direction shows as a corner.
Preview
Installation
FAQ
How are the segments straight?
Line sets type to linear, so each desktop value connects to the next with a straight stroke. dot is false, stroke is var(--color-desktop), and strokeWidth is 2.
Where does the line color come from?
config sets desktop to the label Desktop and color var(--chart-1). ChartContainer writes --color-desktop for the stroke.
How are the month ticks shortened?
XAxis uses dataKey month and tickFormatter set to formatMonth, which returns the first three characters. axisLine and tickLine are false, and tickMargin is 8.
What are the side margins for?
LineChart sets margin to 12 on the left and right. CartesianGrid sets vertical to false, and LineChart sets accessibilityLayer.
Related
- A line chartA line chart drawing one series as a
- A line chart with stepA line chart with step interpolation
- A linear area chartAn area chart that joins its monthly
- A line chart with dotsA line chart with a dot on every data
- A bar chartA bar chart with rounded corners
- A multiple line chartA line chart comparing desktop and mobile