Skip to content
ChartslibraryUI Get Pro

Line chart

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

FreeMIT · install in one command<LineChart />

When to use

  • One metric over time, or up to four that share a unit
  • Actual against plan or last year on the same scale
  • One highlighted series against grey context series
  • Rates that move in a narrow band (set zero={false})

When not to use

Good practice

  • Write the takeaway as the title and the unit and period in the subtitle.
  • Use forecastFrom so forecast periods are dashed and shaded, never mistaken for actuals.
  • Leave missing values as null; the chart draws a gap and says how many are missing.
  • Use highlight to put one series in colour and the rest in grey.

Installation

Line chart is free under the MIT license.

$ npx shadcn@latest add https://chartslibraryui.com/r/line-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

Usage

import { LineChart } from "@/components/charts/line-chart";
import { saasMrr } from "./sample-data";

export function Example() {
  return (
    <LineChart
      title="MRR has run ahead of plan since March"
      subtitle="Monthly recurring revenue, USD"
      data={saasMrr}
      x="month"
      series={[
        { key: "mrr", label: "MRR" },
        { key: "plan", label: "Plan", color: "var(--clui-context)", dashed: true },
      ]}
      format="currency"
      zero={false}
      source="Synthetic data"
    />
  );
}

Data

An array of rows, one per period, with an x key (label or date) and one numeric key per series. null for missing values.

[{ month: "Jan 26", revenue: 1840000, plan: 1800000 }, ...]

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

// LineChartProps = SeriesChartProps (from core/series.tsx)
export interface SeriesChartProps extends FrameProps {
  data: Row[];
  /** Key of the x value in each row. */
  x: string;
  series: SeriesInput[];
  /** "category" treats x as labels (default); "time" reads ISO strings, Date or ms and spaces by real time. */
  xType?: "category" | "time";
  /** Date grain used to label time axes and tooltips. Auto-detected if omitted. */
  grain?: DateGrain;
  /** Y value format, e.g. "currency", { kind: "percent" }, or a function. */
  format?: FormatInput;
  curve?: Curve;
  /** Series key(s) to emphasise; others are drawn as grey context. */
  highlight?: string | string[];
  /** First x value that is a forecast. From there on lines are dashed and the region is shaded. */
  forecastFrom?: string | number | Date;
  /** First x value that is an incomplete period (e.g. month to date). */
  partialFrom?: string | number | Date;
  /** Include zero in the y axis. Default true; set false to zoom in on a rate (lines only). */
  zero?: boolean;
  /** Fixed y domain; null keeps the computed bound. */
  yDomain?: [number | null, number | null];
  references?: Reference[];
  /** Dots on every point. Default: only when there are few points. */
  markers?: boolean;
  /** Series names at the line ends. Default: on when up to 4 series fit. */
  endLabels?: boolean;
  /** Show the legend. Default: on for 2+ series. */
  legend?: boolean;
  /** Click legend entries to hide/show series. Default true for 2+ series. */
  toggleable?: boolean;
}

Source

Installs line-chart.tsx and the shared core/ (11 files).

View line-chart.tsx
"use client";

import { SeriesChart, type SeriesChartProps } from "./core/series";

export type LineChartProps = SeriesChartProps;

/**
 * Trends over time for one to four series. Missing values break the line (never interpolated).
 *
 * @example
 * <LineChart data={rows} x="month" series={[{ key: "revenue", label: "Revenue" }]} format="currency" />
 */
export function LineChart(props: LineChartProps) {
  return <SeriesChart kind="line" summaryName="line" {...props} />;
}

Area chart

A line with a light wash to zero, for volume over time.

Step line chart

Values that change on a date and hold: prices, rates, headcount.

Index chart

Measures in different units rebased to 100, so growth compares on one honest axis.