Skip to content
ChartslibraryUI
Get Pro

React timeline chart

Events and milestones on one time axis, in lanes, with names that never overlap.

FreeMIT · install in one command<TimelineChart />

A timeline chart puts events on one time axis: releases, milestones, incidents, launches. Single dates are drawn as diamonds; rows with an end date are drawn as bars, such as a beta period or a campaign.

Add a lane key to give each team, product or platform its own row and colour. Within a lane, names are placed next to their marks and moved to a new line only when they would overlap, so every name stays readable without a legend. Dates are read as ISO strings, Date objects or timestamps in UTC, and rows without a readable date are listed in a note rather than dropped silently. A today line marks where the plan meets the present.

Use it for history and plans at a glance. For tasks with owners, durations and progress, use a Gantt chart; for a number that changes over time, use a line chart.

When to use

  • Release history by product or platform
  • Project milestones and phases
  • Incidents, launches or campaigns over a year

When not to use

  • Tasks with durations, owners and progress – use Gantt chart
  • A value that changes over time – use Line chart

Good practice

  • Use lanes for teams or products, not for every event.
  • Keep event names short; details go in the tooltip.
  • Add a today line when the timeline runs into the future.

Installation

Timeline chart is free under the MIT license.

pnpm dlx shadcn@latest add https://chartslibraryui.com/r/timeline-chart.json

Installs the chart, its dependencies and the shared core into your components folder.

Then import the theme once: import "@/components/charts/core/charts.css" Installation guide

Building with an AI tool? Download the timeline chart for your AI tool and attach it to Claude, ChatGPT, Lovable or Cursor. No terminal needed. How it works

Usage

import { TimelineChart } from "@/components/charts/timeline-chart";
import { releases } from "./sample-data";

export function Example() {
  return (
    <TimelineChart
      title="13 releases in just over a year, on every platform"
      subtitle="Product releases by platform; bars are beta periods"
      data={releases}
      date="date"
      end="end"
      label="name"
      lane="platform"
    />
  );
}

Data

One row per event with a date key and a name key; optional end-date key for spans and a lane key for rows.

[{ name: "SSO", platform: "Web app", date: "2025-05-20" }, ...]

Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data

Props

Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API

export interface TimelineChartProps extends FrameProps {
  /** Rows to draw, one event per row. See the Data section for the shape. */
  data: Row[];
  /** Key of the event date (ISO string, Date or ms). For spans, the start. */
  date: string;
  /** Key of an optional end date. Rows with an end are drawn as spans. */
  end?: string;
  /** Key of the event name. */
  label: string;
  /** Optional key of the lane (team, product, workstream). Each lane gets its own row and colour. */
  lane?: string;
  /** Draw a "today" line at this date. */
  today?: string | number | Date;
  /** Date grain for the axis and tooltips. Auto-detected from the date range if omitted. */
  grain?: DateGrain;
}

Source

Installs timeline-chart.tsx and the shared core/ (12 files).

View timeline-chart.tsx
"use client";

import { useMemo, type PointerEvent } from "react";
import { AXIS_FONT, axisWidth } from "./core/axis";
import { color as tokens } from "./core/color";
import { parseDate, type Issue, type Row } from "./core/data";
import { formatDate, type DateGrain } from "./core/format";
import { ChartFrame, ChartTooltip, localPoint, useActiveIndex, type FrameProps, type LegendItem } from "./core/frame";
import { linearScale, timeTicks } from "./core/scale";
import { textWidth, truncate } from "./core/text";
import { useWords } from "./core/words";

export interface TimelineChartProps extends FrameProps {
  /** Rows to draw, one event per row. See the Data section for the shape. */
  data: Row[];
  /** Key of the event date (ISO string, Date or ms). For spans, the start. */
  date: string;
  /** Key of an optional end date. Rows with an end are drawn as spans. */
  end?: string;
  /** Key of the event name. */
  label: string;
  /** Optional key of the lane (team, product, workstream). Each lane gets its own row and colour. */
  lane?: string;
  /** Draw a "today" line at this date. */
  today?: string | number | Date;
  /** Date grain for the axis and tooltips. Auto-detected from the date range if omitted. */
  grain?: DateGrain;
}

interface Event {
  name: string;
  lane: number;
  t0: number;
  t1: number | null;
  row: Row;
}

const DAY = 86_400_000;
const ROW_H = 24;
const FONT = 11;

/**
 * Events and milestones on one time axis, in lanes, with names placed so they never overlap. Use it for release
 * history, project milestones or incidents. For tasks with durations and dependencies, use a Gantt chart.
 */
export function TimelineChart({ data, date, end, label, lane, today, grain, height: hProp, ...frame }: TimelineChartProps) {
  const L = useWords(frame.words);
  const prep = useMemo(() => {
    const issues: Issue[] = [];
    if (!Array.isArray(data) || !data.length) return { events: [] as Event[], lanes: [] as string[], issues: [{ level: "error", message: "No data to display." }] as Issue[] };
    const lanes: string[] = [];
    const events: Event[] = [];
    let bad = 0;
    let backwards = 0;
    for (const r of data) {
      const t0 = parseDate(r?.[date]);
      if (t0 === null) {
        bad++;
        continue;
      }
      let t1 = end ? parseDate(r?.[end]) : null;
      if (t1 !== null && t1 < t0) {
        backwards++;
        t1 = null;
      }
      const ln = lane ? String(r?.[lane] ?? "") : "";
      let li = lanes.indexOf(ln);
      if (li < 0) li = lanes.push(ln) - 1;
      events.push({ name: String(r?.[label] ?? ""), lane: li, t0, t1: t1 !== null && t1 > t0 ? t1 : null, row: r });
    }
    if (bad && !events.length) issues.push({ level: "error", message: `No row has a readable date in "${date}".` });
    else if (bad) issues.push({ level: "note", message: `${bad} row(s) without a readable date are not drawn.` });
    if (backwards) issues.push({ level: "warning", message: `${backwards} event(s) end before they start; drawn as single dates.` });
    events.sort((a, b) => a.lane - b.lane || a.t0 - b.t0);
    return { events, lanes, issues };
  }, [data, date, end, label, lane]);
  const { events, lanes } = prep;
  const todayT = today !== undefined ? parseDate(today) : null;
  const times = events.flatMap((e) => (e.t1 !== null ? [e.t0, e.t1] : [e.t0])).concat(todayT !== null ? [todayT] : []);
  const tMin = times.length ? Math.min(...times) : 0;
  const tMax = times.length ? Math.max(...times) : 0;
  const pad = Math.max((tMax - tMin) * 0.03, tMax === tMin ? 15 * DAY : 0);
  const domain: [number, number] = [tMin - pad, tMax + pad];
  const g = grain ?? (tMax - tMin > 3 * 365 * DAY ? "year" : tMax - tMin > 120 * DAY ? "month" : tMax - tMin > 21 * DAY ? "week" : "day");
  const legend: LegendItem[] | undefined = lanes.length > 1 ? lanes.slice(0, 8).map((n, i) => ({ key: `l${i}`, label: n || "—", color: tokens.series(i), shape: "dot" as const })) : undefined;
  const table = {
    columns: [
      { key: "name", label },
      ...(lane ? [{ key: "lane", label: lane }] : []),
      { key: "t0", label: date, format: (v: unknown) => (typeof v === "number" ? formatDate(v, "day", "long") : "") },
      ...(end ? [{ key: "t1", label: end, format: (v: unknown) => (typeof v === "number" ? formatDate(v, "day", "long") : "") }] : []),
    ],
    rows: events.map((e) => ({ name: e.name, lane: lanes[e.lane], t0: e.t0, t1: e.t1 })),
  };
  const summary = `Timeline of ${events.length} event(s)${lanes.length > 1 ? ` in ${lanes.length} lanes` : ""}, from ${times.length ? formatDate(tMin, "day", "long") : "–"} to ${
    times.length ? formatDate(tMax, "day", "long") : "–"
  }. ${events
    .slice(0, 8)
    .map((e) => `${formatDate(e.t0, "day")}: ${e.name}`)
    .join("; ")}.`;
  return (
    <ChartFrame {...frame} height={hProp ?? 0} issues={prep.issues} table={table} summary={summary} legend={legend}>
      {({ width }) => <Plot {...{ width, events, lanes, domain, grain: g, todayT, todayLabel: L.today, fixedHeight: hProp }} />}
    </ChartFrame>
  );
}

function Plot(p: { width: number; events: Event[]; lanes: string[]; domain: [number, number]; grain: DateGrain; todayT: number | null; todayLabel: string; fixedHeight?: number }) {
  const { width, events, lanes, domain } = p;
  const showLanes = lanes.length > 1 || (lanes.length === 1 && lanes[0] !== "");
  const left = showLanes ? Math.min(width * 0.28, axisWidth(lanes.map((l) => l || "—"), AXIS_FONT, 16)) : 8;
  const right = width - 12;
  const x = linearScale(domain, [left, right]);
  // greedy placement: each event takes the first sub-row where its mark and name fit
  const placed = events.map((e) => {
    const x0 = x(e.t0);
    const x1 = e.t1 !== null ? x(e.t1) : x0;
    const w = textWidth(e.name, FONT);
    const inside = e.t1 !== null && x1 - x0 > w + 12;
    // near the right edge, put the name on the left of the mark when there is more room there
    const rightRoom = right - (x1 + 9);
    const leftRoom = x0 - 9 - left;
    const flip = !inside && w > rightRoom && leftRoom > rightRoom;
    const labelX = inside ? x0 + 6 : flip ? x0 - 9 : x1 + 9;
    const text = truncate(e.name, inside ? x1 - x0 - 12 : Math.max(30, flip ? leftRoom : rightRoom), FONT);
    const tw = textWidth(text, FONT);
    const from = flip ? labelX - tw - 4 : Math.min(x0 - 6, labelX);
    const to = (inside ? x1 : flip ? x1 + 6 : labelX + tw) + 10;
    return { e, x0, x1, inside, flip, labelX, text, from, to, sub: 0 };
  });
  const laneRows: number[] = lanes.map(() => 1);
  for (let li = 0; li < lanes.length; li++) {
    const ends: number[] = [];
    for (const pl of placed) {
      if (pl.e.lane !== li) continue;
      let s = ends.findIndex((endX) => endX <= pl.from);
      if (s < 0) s = ends.push(pl.to) - 1;
      else ends[s] = pl.to;
      pl.sub = s;
    }
    laneRows[li] = Math.max(1, ends.length);
  }
  const laneTop: number[] = [];
  let yAcc = 6;
  for (let li = 0; li < lanes.length; li++) {
    laneTop.push(yAcc);
    yAcc += laneRows[li] * ROW_H + 8;
  }
  const plotBottom = yAcc;
  const height = p.fixedHeight ?? plotBottom + 26;
  const { ticks } = timeTicks(domain[0], domain[1], Math.max(2, Math.floor((right - left) / 80)));
  const { active, setActive, keyProps } = useActiveIndex(placed.length, { describe: (i) => ({ label: placed[i]?.e.name, row: placed[i]?.e.row }) });
  const yOf = (pl: (typeof placed)[number]) => laneTop[pl.e.lane] + pl.sub * ROW_H + ROW_H / 2;
  const onMove = (e: PointerEvent<SVGRectElement>) => {
    const pt = localPoint(e);
    let best = -1;
    let bestD = 24;
    placed.forEach((pl, i) => {
      const dy = Math.abs(yOf(pl) - pt.y);
      if (dy > ROW_H / 2) return;
      const dx = pt.x < pl.from ? pl.from - pt.x : pt.x > pl.to ? pt.x - pl.to : 0;
      if (dx < bestD) {
        bestD = dx;
        best = i;
      }
    });
    setActive(best >= 0 ? best : null);
  };
  const tipFor = (pl: (typeof placed)[number]) => {
    const rows = [{ label: pl.e.t1 !== null ? "Start" : "Date", value: formatDate(pl.e.t0, "day", "long"), color: tokens.series(pl.e.lane), shape: "dot" as const, strong: true }];
    if (pl.e.t1 !== null) {
      rows.push({ label: "End", value: formatDate(pl.e.t1, "day", "long"), color: tokens.series(pl.e.lane), shape: "dot" as const, strong: false });
      rows.push({ label: "Duration", value: `${Math.round((pl.e.t1 - pl.e.t0) / DAY)} days`, color: "", shape: "dot" as const, strong: false });
    }
    if (showLanes) rows.push({ label: "Lane", value: lanes[pl.e.lane] || "—", color: "", shape: "dot" as const, strong: false });
    return rows.map((r) => (r.color ? r : { label: r.label, value: r.value }));
  };
  return (
    <>
      <svg width={width} height={height} role="group" aria-roledescription="chart" aria-label="Timeline. Use arrow keys to read events." {...keyProps}>
        {ticks.map((t, i) => (
          <g key={i} aria-hidden>
            <line x1={x(t)} x2={x(t)} y1={2} y2={plotBottom} style={{ stroke: "var(--clui-grid)" }} />
            <text x={x(t)} y={plotBottom + 16} textAnchor="middle" className="clui-tick">
              {formatDate(t, p.grain)}
            </text>
          </g>
        ))}
        {showLanes &&
          lanes.map((ln, li) => (
            <g key={li} aria-hidden>
              {li > 0 && <line x1={0} x2={right} y1={laneTop[li] - 4} y2={laneTop[li] - 4} style={{ stroke: "var(--clui-grid)" }} />}
              <text x={left - 12} y={laneTop[li] + ROW_H / 2} dy="0.32em" textAnchor="end" className="clui-tick" style={{ fill: "var(--clui-ink)" }}>
                {truncate(ln || "—", left - 16, AXIS_FONT)}
              </text>
            </g>
          ))}
        {p.todayT !== null && (
          <g aria-hidden>
            <line x1={x(p.todayT)} x2={x(p.todayT)} y1={0} y2={plotBottom} style={{ stroke: "var(--clui-ink-2)" }} strokeDasharray="3 3" />
            <text x={x(p.todayT) + 4} y={plotBottom - 4} className="clui-annot clui-halo">
              {p.todayLabel}
            </text>
          </g>
        )}
        {placed.map((pl, i) => {
          const y = yOf(pl);
          const c = tokens.series(pl.e.lane);
          return (
            <g key={i} className={`clui-mark${active !== null && active !== i ? " clui-dim" : ""}`}>
              {pl.e.t1 !== null ? (
                <rect x={pl.x0} y={y - 6} width={Math.max(2, pl.x1 - pl.x0)} height={12} rx={2} style={{ fill: c, fillOpacity: pl.inside ? 0.9 : 1 }} />
              ) : (
                <rect x={pl.x0 - 5} y={y - 5} width={10} height={10} transform={`rotate(45 ${pl.x0} ${y})`} style={{ fill: c, stroke: "var(--clui-surface)" }} strokeWidth={1.5} />
              )}
              <text x={pl.labelX} y={y} dy="0.32em" textAnchor={pl.flip ? "end" : "start"} className={pl.inside ? "clui-label" : "clui-label clui-halo"} style={{ fill: pl.inside ? tokens.seriesInk(pl.e.lane) : "var(--clui-ink)" }}>
                {pl.text}
              </text>
            </g>
          );
        })}
        <rect x={0} y={0} width={width} height={plotBottom} fill="transparent" onPointerMove={onMove} onPointerLeave={() => setActive(null)} />
      </svg>
      {active !== null && placed[active] && (
        <ChartTooltip x={placed[active].x1} y={yOf(placed[active])} width={width} height={height} data={{ title: placed[active].e.name, rows: tipFor(placed[active]) }} />
      )}
    </>
  );
}
Pro

Gantt chart

A project plan on a timeline, with progress, milestones and a today line.

Line chart

Trends over time for one to four series, with gaps for missing data and marked forecasts.

Sign in to ChartslibraryUI

New here? The same step creates your account.

Continue with Google
or

No password needed. Bought Pro? Use the email you paid with and your license is there. By signing in you agree to the Terms and Privacy policy.