Chart Topic
Line Chart
Sat Mar 14 2026
最常用的趋势图表,适合展示时间序列、阶段变化、增长节奏和拐点。
为什么它几乎永远有用
当横轴是时间、阶段或任何天然有顺序的维度时,折线图几乎总能比柱状图更顺畅地表达变化过程。
"use client";import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig,} from "@/components/ui/chart";const data = [ { week: "W1", trial: 2.8, paid: 1.2 }, { week: "W2", trial: 3.5, paid: 1.6 }, { week: "W3", trial: 3.2, paid: 1.8 }, { week: "W4", trial: 4.1, paid: 2.2 }, { week: "W5", trial: 4.8, paid: 2.7 }, { week: "W6", trial: 5.4, paid: 3.1 },];const chartConfig = { trial: { label: "Trial", color: "var(--new-home-accent-2)", }, paid: { label: "Paid", color: "var(--new-home-accent-4)", },} satisfies ChartConfig;export function LineChartDemo() { return ( <ChartContainer config={chartConfig} className="min-h-[320px] w-full"> <LineChart data={data} margin={{ top: 12, right: 12, left: -12 }}> <CartesianGrid strokeDasharray="3 3" vertical={false} /> <XAxis dataKey="week" tickLine={false} axisLine={false} /> <YAxis tickLine={false} axisLine={false} width={30} /> <ChartTooltip content={<ChartTooltipContent formatter={(value) => `${value}%`} />} /> <ChartLegend content={<ChartLegendContent />} /> <Line dataKey="trial" type="monotone" stroke="var(--color-trial)" strokeWidth={3} dot={{ fill: "var(--color-trial)", r: 4 }} activeDot={{ r: 6 }} /> <Line dataKey="paid" type="monotone" stroke="var(--color-paid)" strokeWidth={3} dot={{ fill: "var(--color-paid)", r: 4 }} activeDot={{ r: 6 }} /> </LineChart> </ChartContainer> );}适合什么场景
- 周活、日活、营收、转化率的时间趋势
- 版本发布前后、活动前后的波动对比
- 两条或三条曲线之间的走势关系
不太适合的地方
- 时间粒度混乱时,线条会制造误导
- 系列过多时会变成“彩线墙”
- 如果重点不是过程而是单点大小,柱状图可能更直接
实现要点
- 统一时间粒度,例如都按周或都按月。
- 限制线条数量,让主线更突出。
- 对峰值、低谷、关键节点增加注释,会显著提升叙事能力。
代码说明
这个页面里的版本强调“可读的双序列趋势对比”。后续你可以在这个专题下继续补充 spline line、step line、带 reference line 的增长故事版本。