Skip to content
ChartslibraryUI
Get Pro

React uptime chart

Status-page bars per service per day, operational, degraded or down, with uptime and an SLO target.

FreeMIT · install in one command<UptimeChart />

An uptime chart is the row of small bars you know from status pages: one row per service, one bar per day, green when the service was operational, amber when it was degraded and red when it was down. Next to each service is its uptime for the period.

Pass daily uptime as a share and the chart sorts each day for you (below 99.9% is degraded and below 99% is down by default; both are props), or pass status words such as "operational", "partial outage" or "major outage" straight from an incident log. Set a target, such as 99.9%, and any service that missed it is flagged in words. Problem days also get a dot under the bar, so the chart reads without colour, and the table counts the operational, degraded and down days per service.

For a metric like latency, use a line chart or a control chart instead.

When to use

  • Status pages and service health dashboards
  • SLO reporting per service
  • Incident history for a customer report

When not to use

Good practice

  • Show 30 or 90 days; more makes the bars too thin.
  • Set the target your customers were promised.
  • Say how uptime is measured in the subtitle.

Installation

Uptime chart is free under the MIT license.

pnpm dlx shadcn@latest add https://chartslibraryui.com/r/uptime-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 uptime chart for your AI tool and attach it to Claude, ChatGPT, Lovable or Cursor. No terminal needed. How it works

Usage

import { UptimeChart } from "@/components/charts/uptime-chart";
import { serviceUptime } from "./sample-data";

export function Example() {
  return (
    <UptimeChart
      title="Webhooks missed its 99.9% target; every other service stayed above it"
      subtitle="Daily uptime by service, last 90 days"
      data={serviceUptime}
      label="service"
      x="day"
      value="uptime"
      target={0.999}
    />
  );
}

Data

One row per service per period (day) with an uptime share (0 to 1) or a status word.

[{ service: "API", day: "Sep 2", uptime: 0.9998 }, ...]

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 UptimeChartProps extends FrameProps {
  /** One row per service per period (usually a day). See the Data section for the shape. */
  data: Row[];
  /** Key of the service or system name. */
  label: string;
  /** Key of the period label (e.g. a date). Periods are drawn in order of first appearance. */
  x: string;
  /** Key of the uptime share for the period, 0 to 1 (0 to 100 is read as percent). */
  value?: string;
  /** Key of a status word instead of, or on top of, `value`: "up", "degraded" or "down" (also "operational", "partial", "outage"…). */
  status?: string;
  /** Uptime below this is "degraded". Default 0.999 (99.9%). */
  degradedBelow?: number;
  /** Uptime below this is "down". Default 0.99 (99%). */
  downBelow?: number;
  /** Optional target (SLO), e.g. 0.999. Services whose period uptime falls below it are flagged. */
  target?: number;
}

Source

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

View uptime-chart.tsx
"use client";

import { useMemo } from "react";
import { AXIS_FONT } from "./core/axis";
import { color as tokens } from "./core/color";
import { readNum, type Issue, type Row } from "./core/data";
import { formatShare } from "./core/format";
import { ChartFrame, ChartTooltip, useActiveIndex, type FrameProps, type LegendItem } from "./core/frame";
import { textWidth, truncate } from "./core/text";

export type UptimeStatus = "up" | "degraded" | "down" | "none";

export interface UptimeChartProps extends FrameProps {
  /** One row per service per period (usually a day). See the Data section for the shape. */
  data: Row[];
  /** Key of the service or system name. */
  label: string;
  /** Key of the period label (e.g. a date). Periods are drawn in order of first appearance. */
  x: string;
  /** Key of the uptime share for the period, 0 to 1 (0 to 100 is read as percent). */
  value?: string;
  /** Key of a status word instead of, or on top of, `value`: "up", "degraded" or "down" (also "operational", "partial", "outage"…). */
  status?: string;
  /** Uptime below this is "degraded". Default 0.999 (99.9%). */
  degradedBelow?: number;
  /** Uptime below this is "down". Default 0.99 (99%). */
  downBelow?: number;
  /** Optional target (SLO), e.g. 0.999. Services whose period uptime falls below it are flagged. */
  target?: number;
}

interface Service {
  name: string;
  cells: { value: number | null; status: UptimeStatus }[];
  uptime: number | null;
  counts: Record<UptimeStatus, number>;
}

const WORDS: Record<UptimeStatus, string> = { up: "Operational", degraded: "Degraded", down: "Down", none: "No data" };

function readStatus(raw: unknown): UptimeStatus | null {
  if (raw === null || raw === undefined) return null;
  const s = String(raw).trim().toLowerCase();
  if (!s) return null;
  if (/^(up|ok|operational|healthy|green|online|available)$/.test(s)) return "up";
  if (/^(degraded|partial|partial outage|minor|warning|warn|yellow|amber|maintenance|degraded performance)$/.test(s)) return "degraded";
  if (/^(down|outage|major|major outage|critical|red|offline|unavailable|failed)$/.test(s)) return "down";
  return null;
}

/**
 * Service health over time, status-page style: one row of bars per service, one bar per day, coloured operational,
 * degraded or down, with the uptime for the period and an optional target. Problem days are also marked with a dot,
 * so the status never relies on colour alone.
 */
export function UptimeChart({ data, label, x, value, status, degradedBelow = 0.999, downBelow = 0.99, target, height: hProp, ...frame }: UptimeChartProps) {
  const prep = useMemo(() => {
    const issues: Issue[] = [];
    if (!Array.isArray(data) || !data.length) return { services: [] as Service[], periods: [] as string[], issues: [{ level: "error", message: "No data to display." }] as Issue[] };
    if (!value && !status) return { services: [] as Service[], periods: [] as string[], issues: [{ level: "error", message: "Pass `value` (uptime share) or `status` (a status word)." }] as Issue[] };
    const periods: string[] = [];
    const names: string[] = [];
    const cell = new Map<string, { value: number | null; status: UptimeStatus | null }>();
    let invalid = 0;
    let unknownStatus = 0;
    let dupes = 0;
    let percentScale = false;
    if (value) {
      const nums = data.map((r) => readNum(r?.[value])).filter((n) => n.state === "ok" && n.value !== null).map((n) => n.value!);
      percentScale = nums.length > 0 && nums.some((v) => v > 1) && nums.every((v) => v <= 100);
    }
    for (const r of data) {
      const name = String(r?.[label] ?? "").trim() || "(blank)";
      const p = String(r?.[x] ?? "").trim();
      if (!p) continue;
      if (!names.includes(name)) names.push(name);
      if (!periods.includes(p)) periods.push(p);
      let v: number | null = null;
      if (value) {
        const n = readNum(r?.[value]);
        if (n.state === "invalid") invalid++;
        else if (n.value !== null) v = percentScale ? n.value / 100 : n.value;
      }
      let st: UptimeStatus | null = null;
      if (status) {
        const raw = r?.[status];
        st = readStatus(raw);
        if (st === null && raw !== null && raw !== undefined && String(raw).trim() !== "") unknownStatus++;
      }
      const key = `${name}\u0000${p}`;
      if (cell.has(key)) dupes++;
      cell.set(key, { value: v, status: st });
    }
    if (invalid) issues.push({ level: "error", message: `"${value}" has ${invalid} non-numeric value(s).` });
    if (percentScale) issues.push({ level: "note", message: `"${value}" looks like percentages (0 to 100), so it is read as percent.` });
    if (unknownStatus) issues.push({ level: "note", message: `${unknownStatus} status value(s) weren't recognised and are drawn from the uptime value, or as no data.` });
    if (dupes) issues.push({ level: "warning", message: `${dupes} duplicate service/period row(s); the last one is shown.` });
    const classify = (v: number | null, st: UptimeStatus | null): UptimeStatus => {
      if (st) return st;
      if (v === null) return "none";
      return v < downBelow ? "down" : v < degradedBelow ? "degraded" : "up";
    };
    let gaps = 0;
    const services: Service[] = names.map((name) => {
      const cells = periods.map((p) => {
        const c = cell.get(`${name}\u0000${p}`);
        const st = classify(c?.value ?? null, c?.status ?? null);
        if (st === "none") gaps++;
        return { value: c?.value ?? null, status: st };
      });
      const counts: Record<UptimeStatus, number> = { up: 0, degraded: 0, down: 0, none: 0 };
      cells.forEach((c) => counts[c.status]++);
      const vals = cells.map((c) => c.value).filter((v): v is number => v !== null);
      // uptime for the period: the average of the values; with status words only, the share of periods that were up
      const known = counts.up + counts.degraded + counts.down;
      const uptime = vals.length ? vals.reduce((a, b) => a + b, 0) / vals.length : known ? counts.up / known : null;
      return { name, cells, uptime, counts };
    });
    if (gaps) issues.push({ level: "note", message: `${gaps} service-period(s) have no data and are drawn grey.` });
    if (!value && status) issues.push({ level: "note", message: "Uptime is the share of periods marked up (no uptime values were given)." });
    return { services, periods, issues };
  }, [data, label, x, value, status, degradedBelow, downBelow]);

  const { services, periods } = prep;
  const rowH = 54;
  const height = hProp ?? Math.max(110, services.length * rowH + 30);
  const legend: LegendItem[] = (["up", "degraded", "down", "none"] as UptimeStatus[]).map((s) => ({ key: s, label: WORDS[s], color: fillOf(s), shape: "square" as const }));
  const pctFmt = (v: unknown) => (v === null || v === undefined ? "–" : formatShare(v as number, 2));
  const table = {
    columns: [
      { key: "name", label },
      { key: "uptime", label: "Uptime", align: "right" as const, format: pctFmt },
      { key: "up", label: WORDS.up, align: "right" as const },
      { key: "degraded", label: WORDS.degraded, align: "right" as const },
      { key: "down", label: WORDS.down, align: "right" as const },
      { key: "none", label: WORDS.none, align: "right" as const },
    ],
    rows: services.map((s) => ({ name: s.name, uptime: s.uptime, ...s.counts })),
  };
  const summary = `Uptime of ${services.length} service(s) over ${periods.length} period(s), ${periods[0] ?? ""} to ${periods[periods.length - 1] ?? ""}. ${services
    .map((s) => `${s.name}: ${s.uptime === null ? "no data" : formatShare(s.uptime, 2)}, ${s.counts.degraded} degraded and ${s.counts.down} down`)
    .join("; ")}.`;
  return (
    <ChartFrame {...frame} height={height} issues={prep.issues} table={table} summary={summary} legend={legend}>
      {({ width }) => <Rows {...{ width, height, services, periods, rowH, target }} />}
    </ChartFrame>
  );
}

function fillOf(s: UptimeStatus) {
  return s === "up" ? tokens.good : s === "degraded" ? tokens.warn : s === "down" ? tokens.bad : tokens.grid;
}

function Rows({ width, height, services, periods, rowH, target }: { width: number; height: number; services: Service[]; periods: string[]; rowH: number; target?: number }) {
  const n = periods.length;
  const { active, setActive, keyProps } = useActiveIndex(services.length * n, {
    columns: n,
    describe: (i) => ({ label: `${services[Math.floor(i / n)]?.name}, ${periods[i % n]}` }),
  });
  const left = 0;
  const right = width;
  const slot = (right - left) / Math.max(1, n);
  const gap = slot >= 6 ? 2 : slot >= 3 ? 1 : 0;
  const barW = Math.max(1, slot - gap);
  const barH = 24;
  const a = active !== null ? { s: Math.floor(active / n), p: active % n } : null;
  const axisY = services.length * rowH + 8;
  return (
    <>
      <svg width={width} height={height} role="group" aria-roledescription="chart" aria-label="Uptime chart. Use arrow keys to move between services and periods." {...keyProps}>
        {services.map((s, si) => {
          const y0 = si * rowH;
          const by = y0 + 20;
          const below = target !== undefined && s.uptime !== null && s.uptime < target;
          const upText = s.uptime === null ? "No data" : formatShare(s.uptime, 2);
          const upW = textWidth(upText, AXIS_FONT) + (below ? textWidth(` · below ${formatShare(target!, 1)} target`, 10.5) : 0);
          return (
            <g key={s.name}>
              <text x={left} y={y0 + 8} dy="0.32em" className="clui-tick" style={{ fill: "var(--clui-ink)", fontWeight: 600 }}>
                {truncate(s.name, Math.max(40, width - upW - 16), AXIS_FONT)}
              </text>
              <text x={right} y={y0 + 8} dy="0.32em" textAnchor="end" className="clui-tick" style={{ fill: below ? tokens.badText : "var(--clui-ink)", fontVariantNumeric: "tabular-nums" }}>
                {upText}
                {below && <tspan style={{ fontSize: 10.5 }}> · below {formatShare(target!, 1)} target</tspan>}
              </text>
              {s.cells.map((c, pi) => {
                const bx = left + pi * slot + gap / 2;
                const on = a === null || (a.s === si && a.p === pi);
                return (
                  <g key={pi} onPointerEnter={() => setActive(si * n + pi)} onPointerLeave={() => setActive(null)}>
                    <rect x={bx} y={by} width={barW} height={barH} rx={Math.min(2, barW / 2)} style={{ fill: fillOf(c.status), opacity: on ? 1 : 0.55 }} />
                    {(c.status === "degraded" || c.status === "down") && (
                      <circle cx={bx + barW / 2} cy={by + barH + 5} r={c.status === "down" ? 2.2 : 1.6} style={{ fill: "var(--clui-ink-2)" }} aria-hidden />
                    )}
                    <rect x={left + pi * slot} y={by - 2} width={slot} height={barH + 10} fill="transparent" />
                  </g>
                );
              })}
            </g>
          );
        })}
        {n > 0 && (
          <g aria-hidden>
            <text x={left} y={axisY + 6} dy="0.32em" className="clui-tick">
              {periods[0]}
            </text>
            {n > 1 && (
              <text x={right} y={axisY + 6} dy="0.32em" textAnchor="end" className="clui-tick">
                {periods[n - 1]}
              </text>
            )}
          </g>
        )}
        {a && (
          <rect
            x={left + a.p * slot + gap / 2 - 1.5}
            y={a.s * rowH + 20 - 1.5}
            width={barW + 3}
            height={barH + 3}
            rx={2.5}
            fill="none"
            style={{ stroke: "var(--clui-ink)" }}
            strokeWidth={1.5}
            pointerEvents="none"
          />
        )}
      </svg>
      {a && services[a.s] && (
        <ChartTooltip
          x={left + a.p * slot + slot / 2}
          y={a.s * rowH + 20}
          width={width}
          height={height}
          data={{
            title: `${services[a.s].name} · ${periods[a.p]}`,
            rows: [
              { label: "Status", value: WORDS[services[a.s].cells[a.p].status], color: fillOf(services[a.s].cells[a.p].status), shape: "square", strong: true },
              ...(services[a.s].cells[a.p].value !== null ? [{ label: "Uptime", value: formatShare(services[a.s].cells[a.p].value!, 2) }] : []),
            ],
          }}
        />
      )}
    </>
  );
}
Pro

Control chart

A process over time against its own natural limits, marking the points that are real signals.

KPI row

A responsive row of KPI tiles that wraps cleanly.

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.