Line Chart

A multi-series time plot built on visx. Pass an explicit width; size the container yourself.

Usage

import { LineChart, type LineChartSeries } from '@epilot/spark-ui/line-chart'
function Chart({ width }: { width: number }) {
  return (
    <LineChart
      width={width}
      height={220}
      series={series}
      yAxisUnit="units"
      formatDate={formatHour}
      formatValue={formatValue}
    />
  )
}

LineChart does not observe its container. Measure width with ResizeObserver or @epilot/spark-ui/hooks/use-container-width, and only render once width > 0. For ready-made energy day plots, see Solar Forecast Chart and Power History Chart.

Series stroke colors come from each series' className (Tailwind stroke-* classes). Pass a matching color (CSS value) so the tooltip swatch and hover dot stay in sync when you override the stroke.

Examples

Measured vs projected

Split one curve into a solid measured segment and a dashed projected segment that share a handoff point. Both series use the same color so the tooltip matches the line.

Reference markers

referenceLines draw vertical dashed markers on the time axis. Labels sit near the top of the plot.

API Reference

LineChartProps

PropTypeDefaultDescription
seriesLineChartSeries[]One entry per line. Empty series still reserve a legend/tooltip slot only if they have data points.
widthnumberPlot width in px. Required; the chart does not size itself.
heightnumberPlot height in px.
margin{ top, right, bottom, left }16/16/40/48Inner plot padding. Increase left when y-axis labels are wide.
curve"monotone" | "step" | "step-after" | "step-before" | "linear""monotone"Default interpolation for every series. Per-series curve overrides this.
showGridbooleantrueHorizontal grid lines behind the series.
showTooltipbooleantrueCrosshair + tooltip on hover.
xTickCountnumber5Target number of x-axis ticks.
yTickCountnumber4Target number of y-axis ticks.
yDomain[number, number]data extentFixed y-axis range. When omitted, the domain pads ~10% and pins the baseline at 0 when all values ≥ 0.
formatDate(date: Date) => stringlocale dateX-axis tick labels.
formatTooltipDate(date: Date) => stringformatDateTooltip header. Use a fuller clock time when axis ticks are compact.
formatValue(value: number) => stringlocale numberTooltip values, and y-axis ticks when yAxisUnit is omitted.
yAxisUnitstringUnit drawn once above the y-axis. When set, ticks use the compact shared formatter instead of formatValue.
formatYTick(value: number) => stringcompact ticksOverrides y-axis tick labels when yAxisUnit is set.
referenceLines{ key, date, label? }[]Vertical dashed markers on the time axis.
topContent{ key, date, content }[]HTML nodes pinned above the plot at a time (for example icons).
classNamestringMerges onto the root SVG wrapper.

LineChartSeries

FieldTypeDefaultDescription
idstringStable key. Used as the tooltip label when label is omitted.
dataLineChartDatum[]Sorted ascending by date. Points outside the hovered x-domain are skipped.
labelReactNodeidTooltip row label.
classNamestringpaletteStroke classes for the path (for example stroke-orange-9).
colorstringpaletteCSS color for the tooltip swatch and hover dot. Set whenever className overrides the stroke color.
curveLineChartCurvechart curvePer-series interpolation override.
dashedbooleanfalseDraws the path with a dash pattern.
dashPatternstring"4 4"SVG stroke-dasharray when dashed is true.

LineChartDatum

FieldTypeDescription
dateDateX value (time).
valuenumberY value.

Accessibility

  • The plot is a decorative SVG. Pair it with a text summary or table when the values matter for a decision.
  • Hover tooltips are pointer-only. Do not make the tooltip the only place a value appears.
  • Prefer formatDate / formatValue that read clearly out of context (include units in tooltip values, or set yAxisUnit for the axis).

On this page