Line Chart

Free

12 variants: line, spline, step, dashed, custom animation, inversed, zones, multi-colored, stacked and 100% stacked, plus trend lines and strip lines (free and Pro). A missing reading is drawn as a break in the line, not as a zero. Pure SVG.

</>sv-line-chart chartlinetrend
import { SvLineChartComponent } from '@styloviz/charts/line-chart';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Spline with subtitle

example.htmlAngular
<sv-line-chart
  [categories]="days"
  [series]="series"
  chartType="spline"
  title="Active users"
  subtitle="Last 30 days"
  [height]="300" />

A reading that was never taken

example.htmlAngular
// null is a gap: the line breaks there rather than joining across it.
series = [{ label: 'Sensor', data: [12, 14, null, 19, 21] }];

Preset — time series with zoom

example.htmlAngular
// Long ordered series you scrub through. Dots off (they turn to noise past a
// few hundred points), grid on, brush on, animation off so a re-render during
// a drag does not fight the drag.
options = { showDots: false, showGrid: true, animated: false };
// plus [zoomable]="true" [minZoomPoints]="3" on the Pro chart.

Preset — annotated analytical

example.htmlAngular
// A short series someone is reading closely: every point marked and labelled,
// zones recolouring the line across the thresholds that matter.
options = { showDots: true, showDataLabels: true, showGrid: true, animated: true };
// plus per-series zones: [{ start: 0, end: 40, color: '#f59e0b', label: 'Below target' }]

Large data — thousands of points

example.htmlAngular
<!-- Each horizontal unit of the plot keeps its lowest and highest reading, so
     every peak and trough is drawn; markers are off and the note under the plot
     says how many points were drawn. Hover reads the exact value. -->
<sv-line-chart renderer="large-data" [categories]="timestamps" [series]="readings" />

Export to PNG, SVG or PDF

example.htmlAngular
<!-- npm i @styloviz-pro/export — works around any chart; see /docs/exporting-a-chart -->
<div svChartExport #chart="svChartExport" fileName="revenue">
  <sv-line-chart [categories]="months" [series]="series" />
</div>
<button type="button" (click)="chart.png()">PNG</button>

Preset — compact sparkline

example.htmlAngular
// A trend in a table cell or a stat card: no axes, no grid, no legend, nothing
// but the shape. Reach for <sv-sparkline> if that is all you need.
options = { showDots: false, showGrid: false, showLabels: false, showLegend: false, animated: false };

When to use

  • Showing a trend or change over a continuous/ordered axis (time series).
  • You want multi-series comparison with zones, trend lines or markers.
  • For category comparisons rather than trends, use the Bar Chart.
  • A series of thousands of readings: `renderer="large-data"` draws its outline instead of one vertex per reading.
  • A live feed: `[live]="true"` with `liveWindow` follows the newest readings as you append them (Pro); `sv-live-stream-chart` scrolls a pushed stream. See the Live data guide.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
interactiveLegendbooleantrueLegend entries are keyboard buttons: hover or focus one and the other series fade; Enter, Space or a click hides or shows it; the arrow keys move between series. `false` keeps the static legend. Applies to the series legend — a zoned chart's legend keys zones, not series, and stays static.
hiddenSeriesreadonly string[] (two-way)[]Labels of the series switched off from the legend. Two-way bindable (`[(hiddenSeries)]`) so a host can persist and restore the choice; the last visible series cannot be hidden. The value axis keeps its scale, so hiding a series never silently re-scales the ones left.
categoriesstring[][]Category labels shown on the axis.
seriesLineChartSeries[][]Data series.
chartTypeLineChartType'line'Visual chart type.
rendererLineChartRenderer'standard'`'large-data'` draws a series of thousands of points as its outline — the lowest and highest reading of each horizontal plot unit — instead of one vertex per reading. See `LineChartRenderer`.
titlestring''Chart title.
subtitlestring''Chart subtitle / source attribution shown below the title.
heightnumber300Chart height in px.
optionsLineChartOptions{}Chart-wide display options.
customClassstring''Additional CSS classes on the root element.
ariaLabelstring''Accessible-name override for the chart image. When empty, a concise data summary is generated; the full data is exposed via a visually-hidden table.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
hiddenSeriesChangereadonly string[]Emits the new `hiddenSeries` whenever it changes — the output half of `[(hiddenSeries)]`.

<sv-line-chart-pro>

Also in this family — SvLineChartProComponent from @styloviz-pro/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
interactiveLegendbooleantrueLegend entries are keyboard buttons: hover or focus one and the other series fade; Enter, Space or a click hides or shows it; the arrow keys move between series. `false` keeps the static legend. Applies to the series legend — a zoned chart's legend keys zones, not series, and stays static.
hiddenSeriesreadonly string[] (two-way)[]Labels of the series switched off from the legend. Two-way bindable (`[(hiddenSeries)]`) so a host can persist and restore the choice; the last visible series cannot be hidden. The value axis keeps its scale, so hiding a series never silently re-scales the ones left.
categoriesstring[][]Category labels shown on the axis.
seriesLineChartSeries[][]Data series.
chartTypeLineChartType'line'Visual chart type.
rendererLineChartRenderer'standard'`'large-data'` draws a series of thousands of points as its outline — the lowest and highest reading of each horizontal plot unit — instead of one vertex per reading. See `LineChartRenderer`.
titlestring''Chart title.
subtitlestring''Chart subtitle / source attribution shown below the title.
heightnumber300Chart height in px.
optionsLineChartOptions{}Chart-wide display options.
customClassstring''Additional CSS classes on the root element.
ariaLabelstring''Accessible-name override for the chart image. When empty, a concise data summary is generated; the full data is exposed via a visually-hidden table.
zoomablebooleanfalseShows a draggable brush (range-selector) strip below the chart for zooming and panning the visible category window. Drag a handle to zoom, drag the window itself to pan — one control surface for both, since a brush IS the pan/zoom mechanism, not a third separate feature. Normal layout only (`chartType !== 'inversed'`) — the transposed axes an inversed chart uses would need a vertical brush, which is not provided.
minZoomPointsnumber2Fewest categories that may stay visible when zoomed all the way in — keeps a drag from collapsing the window to nothing.
livebooleanfalseFollow the newest readings: the visible window is the last `liveWindow` categories, and it moves as the host appends to `categories` / `series`. The draw-on animation is off, because a line that redraws itself every tick is motion with no meaning. A brush drag (`zoomable`) still wins — the reader is looking at something — and `resetZoom()` resumes following. The chart never generates data: the host owns the feed (a socket, a poll, a timer) and the retention — keep the arrays bounded, e.g. with `svAppendSample(…, { retain })` from `@styloviz/core`.
liveWindownumber20`live`: how many of the newest categories to show.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
zoomRangeChangeLineChartZoomRangeThe visible window changed — a brush drag (handle resize or pan) finished, a keyboard nudge was applied, or `resetZoom()` was called. Indices are into the full `categories`/series `data` arrays, so a host can slice its own source data to match.
hiddenSeriesChangereadonly string[]Emits the new `hiddenSeries` whenever it changes — the output half of `[(hiddenSeries)]`.

<sv-trend-line-chart>

Also in this family — SvTrendLineChartComponent from @styloviz/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
titlestring''Chart title shown in the header; also the base of the generated accessible name.
subtitlestring''Secondary line shown below the title.
categoriesstring[][]X-axis category labels; each series' `data` is indexed by position against these.
seriesTrendLineSeries[][]Scatter series drawn as dots (optionally connected); `data` holds one value per category, and `null` or non-finite values are gaps left out of the fit.
trendsTrendLineDefinition[][{ type: 'linear' }]Trend lines to render. The switcher overrides `type` for the first trend.
optionsTrendLineChartOptions{}Display options: height, grid, axis labels, legend, dot radius, trend-type switcher, grid divisions and draw-in animation.
customClassstring''Extra CSS classes applied to the root wrapper.
ariaLabelstring''Accessible-name override; otherwise a structure summary is generated.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.

<sv-trend-line-chart-pro>

Also in this family — SvTrendLineChartProComponent from @styloviz-pro/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
titlestring''Chart title shown in the header; also the base of the generated accessible name.
subtitlestring''Secondary line shown below the title.
categoriesstring[][]X-axis category labels; each series' `data` is indexed by position against these.
seriesTrendLineSeries[][]Scatter series drawn as dots (optionally connected); `data` holds one value per category, and `null` or non-finite values are gaps left out of the fit.
trendsTrendLineDefinition[][{ type: 'linear' }]Trend lines to render. The switcher overrides `type` for the first trend.
optionsTrendLineChartOptions{}Display options: height, grid, axis labels, legend, dot radius, trend-type switcher, grid divisions and draw-in animation.
customClassstring''Extra CSS classes applied to the root wrapper.
ariaLabelstring''Accessible-name override; otherwise a structure summary is generated.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.

<sv-strip-line-chart>

Also in this family — SvStripLineChartComponent from @styloviz/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
titlestring''Chart title shown in the header; also the base of the generated accessible name.
subtitlestring''Secondary line shown below the title (rendered only when `title` is set).
categoriesstring[][]X-axis category labels; each series' `data` is indexed by position against these.
seriesStripSeries[][]Line series; `data` holds one value per category, and `null` or non-finite values are gaps that break the line.
stripsStripBand[][]Coloured bands drawn behind the data: horizontal bands span a Y-value range, vertical bands span a category-index range.
optionsStripLineChartOptions{}Display options: height, grid, axis labels, legend, band labels, grid divisions, dots and draw-in animation.
customClassstring''Extra CSS classes applied to the root wrapper.
ariaLabelstring''Accessible-name override; otherwise a structure summary is generated.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.

<sv-strip-line-chart-pro>

Also in this family — SvStripLineChartProComponent from @styloviz-pro/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
titlestring''Chart title shown in the header; also the base of the generated accessible name.
subtitlestring''Secondary line shown below the title (rendered only when `title` is set).
categoriesstring[][]X-axis category labels; each series' `data` is indexed by position against these.
seriesStripSeries[][]Line series; `data` holds one value per category, and `null` or non-finite values are gaps that break the line.
stripsStripBand[][]Coloured bands drawn behind the data: horizontal bands span a Y-value range, vertical bands span a category-index range.
optionsStripLineChartOptions{}Display options: height, grid, axis labels, legend, band labels, grid divisions, dots and draw-in animation.
customClassstring''Extra CSS classes applied to the root wrapper.
ariaLabelstring''Accessible-name override; otherwise a structure summary is generated.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.

<sv-live-stream-chart>

Also in this family — SvLiveStreamChartComponent from @styloviz/charts.

Async states

  • loading
  • empty
  • error
  • retry
  • offline

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
demoFeedbooleanfalseGenerate the stream's points internally, with `Math.random()`. For demos and screenshots only. Off by default; left on, a chart wired to a real feed would draw invented numbers alongside the real ones.
connectionSvConnectionState'idle'State of the socket / `EventSource` behind `push()`. A stream that stops moving looks the same whether the source went quiet or the connection dropped, so the chart cannot infer this — only the host knows. `idle` renders nothing; anything else replaces the LIVE badge with the state.
reconnectablebooleanfalseOffer a Reconnect button while `connection` is `reconnecting` or `closed`. Off by default: most hosts retry on their own, and a second manual trigger opens a second socket.
titlestring'Live Data Stream'Chart title, rendered in the header and used in the default accessible name.
subtitlestring''Secondary line shown under the title; hidden when empty.
seriesLiveStreamSeries[][ { label: 'Sensor A', color: PALETTE[0…The streamed lines, one per entry — `label` for the legend and accessible name, optional `color` (falls back to the palette). `push()` values map to these by index; an empty array shows the empty state.
optionsLiveStreamChartOptions{}Height, visible window size, point interval, smoothing, grid/legend/area toggles and fixed Y range — see `LiveStreamChartOptions`.
ariaLabelstring''Accessible-name override for the chart image.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
reconnectvoidThe user asked to re-open the feed.

<sv-live-stream-chart-pro>

Also in this family — SvLiveStreamChartProComponent from @styloviz-pro/charts.

Async states

  • loading
  • empty
  • error
  • retry
  • offline

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
demoFeedbooleanfalseGenerate the stream's points internally, with `Math.random()`. For demos and screenshots only. Off by default; left on, a chart wired to a real feed would draw invented numbers alongside the real ones.
connectionSvConnectionState'idle'State of the socket / `EventSource` behind `push()`. A stream that stops moving looks the same whether the source went quiet or the connection dropped, so the chart cannot infer this — only the host knows. `idle` renders nothing; anything else replaces the LIVE badge with the state.
reconnectablebooleanfalseOffer a Reconnect button while `connection` is `reconnecting` or `closed`. Off by default: most hosts retry on their own, and a second manual trigger opens a second socket.
titlestring'Live Data Stream'Chart title, rendered in the header and used in the default accessible name.
subtitlestring''Secondary line shown under the title; hidden when empty.
seriesLiveStreamSeries[][ { label: 'Sensor A', color: PALETTE[0…The streamed lines, one per entry — `label` for the legend and accessible name, optional `color` (falls back to the palette). `push()` values map to these by index; an empty array shows the empty state.
optionsLiveStreamChartOptions{}Height, visible window size, point interval, smoothing, grid/legend/area toggles and fixed Y range — see `LiveStreamChartOptions`.
ariaLabelstring''Accessible-name override for the chart image.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
reconnectvoidThe user asked to re-open the feed.

<sv-click-add-point-chart>

Also in this family — SvClickAddPointChartComponent from @styloviz-pro/charts.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Inputs

NameTypeDefaultDescription
titlestring'Click to Add Data Points'Chart title, rendered in the header and used in the default accessible name.
ariaLabelstring''Accessible-name override for the chart image.
optionsClickAddChartOptions{}Height, max points before the plot auto-resets, grid toggle, point/line colors and area fill — see `ClickAddChartOptions`.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Bound to the names this component actually exposes.

usage.htmlAngular
<sv-line-chart
  [series]="series()"
  [loading]="loading()"
  [error]="error()"
  [filtered]="filtered()"
  (retry)="load()"
/>

Host class

Drive the three async inputs from your own fetch.

host.component.tsTypeScript
import { signal } from '@angular/core';
import { toSvDataError, type SvDataError } from '@styloviz/core';
import type { LineChartSeries } from '@styloviz/charts/line-chart';

readonly series = signal<LineChartSeries[]>([]);
readonly loading = signal(false);
readonly error = signal<SvDataError | null>(null);
readonly filtered = signal<boolean>(false);

async load(): Promise<void> {
  this.loading.set(true);
  this.error.set(null);
  try {
    const res = await fetch('/api/series');
    if (!res.ok) throw res;
    this.series.set(await res.json());
  } catch (e) {
    this.error.set(toSvDataError(e));
  } finally {
    this.loading.set(false);
  }
}
  • This component does not emit a query, so it renders what you give it. Call `load()` on your own trigger and bind `series`, `loading` and `error`.
  • Set `filtered` when a search or filter is active. It is the difference between "you have no orders" and "no orders match this filter" — telling a customer with 4,000 orders the first one reads as a bug.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • Interactive legend (both tiers): hover or keyboard-focus an entry and every other series fades; Enter, Space or a click hides or shows it. The hidden set is `[(hiddenSeries)]`, two-way bound so a host can persist it; the last visible series cannot be hidden, and the value axis keeps its scale. `[interactiveLegend]="false"` keeps the static key.
  • Line, spline or step interpolation.
  • Zones, trend lines and strip bands.
  • Multi-series with custom colors and markers.
  • `null` in a series is a gap: the line breaks, no marker is drawn, the filled area stops at the break rather than painting under readings nobody took, and the axis scales to the values that exist. `NaN` and `Infinity` are treated the same way — a chart cannot tell a sensor fault from a `parseFloat('n/a')`.
  • Synchronised groups: `svChartSync="ops"` (from `@styloviz/core`) on several charts shares the hovered category and — from a `zoomable` Pro line chart — the brush window. Matched by category LABEL, so charts with different ranges still line up; a remote change is never re-published. Line and bar charts (both tiers) take part; `injectSvChartSync()` joins your own chart to a group.

Best practices

  • Do: Limit to a few series; too many lines turn into spaghetti. When you cannot, the legend is the way out: focus or hover an entry to fade every other line, or switch series off and back on.
  • Do: Label series in a legend and keep colors consistent across charts.
  • Do: Start from one of the three presets above rather than assembling options from scratch. They are the combinations that are actually tested together, and the ones that go wrong are predictable: dots plus a few hundred points is noise, animation plus a zoom brush fights the drag, and values plus a dense series overlaps into unreadability.
  • Do: Send null for a reading that was never taken. Do NOT send 0 — that asserts a measurement of zero, which is a different claim and one the chart will happily draw a line down to. The gap breaks the line and the chart says how many readings are missing under the plot.
  • Don't: Do not interpolate across a gap before passing the data in. Joining two known readings through an unknown one draws a value nobody recorded, at full confidence, in the middle of the series — and it is indistinguishable from a real measurement once it is on the page.
  • Tip: The line chart has no time zone, and that is the policy. Its x is a list of category STRINGS, so whatever they say is what the axis says — the component never parses a date, never calls toLocaleDateString, and cannot shift a label by an offset. Format your timestamps once, in the zone you mean, before they reach it. If you want the chart to do the formatting, use the Date-Time Category chart (/docs/datetime-chart), which takes ISO strings and reads a bare YYYY-MM-DD as a calendar day in local time rather than as UTC midnight.
  • Tip: A gap in a STACKED chart is the one case the chart cannot honour: every band above it is positioned by the running total, so the missing reading has to count as zero for the stack to add up. That substitution is disclosed under the plot. If the gaps matter more than the totals, use a plain line chart.
  • Tip: Use `spline` for smooth trends and `step` for discrete state changes.

Accessibility

  • The legend is a `role="toolbar"` of `aria-pressed` toggle buttons with ONE tab stop — the keyboard path between series: the arrow keys (and Home/End) move from series to series, each one put in front as focus lands on it, and Enter or Space shows or hides it. Showing and hiding are announced through the live region, and a hidden series stays in the summary table (hiding is a view, not a deletion).
  • The SVG is `role="img"` with an auto-generated data summary (override via `ariaLabel`), backed by an `sv-data-summary-table` of every point and series value — one row per point, one column per series.
  • When `zoomable` is on, the table follows the brush window instead of the full dataset, and adds a line saying which window it is ("Showing points 6–15 of 40."). A table that listed all forty points beside a chart brushed down to ten described points that are not on screen, with no way to tell which ten were — and an alternative that contradicts the picture is worse than none. The free Line Chart has no brush, so it has neither.
  • Series legend is keyboard reachable; reduced-motion disables the draw-on animation.
  • A break in a line is ambiguous on sight — "nothing was recorded here" to one reader, a rendering glitch to another, and easy to miss entirely at one missing point in a dense series. The count of missing readings is stated in text under the plot, so it does not depend on noticing a gap in a drawing.
  • In a sync group, another chart's hover shows here as a tooltip and crosshair at the same category — a pointer convenience; every value stays reachable through the data table, which `svChartDataTable` can also put on screen.

Feedback on Line Chart

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.