ComponentUpdated in v15

Line Chart

One or more series of values as lines.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrLineChart } from 'ngwr/charts/line-chart';

@Component({ imports: [WrLineChart] })
export class MyComponent {}

Multi-series

<wr-line-chart [series]="series" [xLabels]="labels" />
  • Visits
  • Signups
MonTueWedThuFriSatSun

Tooltip

[tooltip]="false" also hides the crosshair and markers.

<wr-line-chart [series]="series" [xLabels]="labels" />
<wr-line-chart [series]="series" [xLabels]="labels" [tooltip]="false" />

On (default)

  • Visits
  • Signups
MonTueWedThuFriSatSun

[tooltip]="false"

  • Visits
  • Signups
MonTueWedThuFriSatSun

Number format

Numbers follow LOCALE_ID, with compact ticks. valueFormat replaces it on the axis and in the tooltip.

<wr-line-chart [series]="revenue" [xLabels]="labels" />
<wr-line-chart [series]="revenue" [xLabels]="labels" [valueFormat]="usd" />
const usdFormat = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
  maximumFractionDigits: 0,
});

usd = (value: number): string => usdFormat.format(value);

Default

  • Revenue
MonTueWedThuFriSatSun

[valueFormat]="usd"

  • Revenue
MonTueWedThuFriSatSun

API

NameDescriptionTypeDefault
seriesOne entry per line. A series with no color takes the next entry from the chart's fallback palette, so several lines are distinguishable unconfigured.readonly WrLineSeries[][]
ariaLabelAccessible name of the chart. The legend carries the series NAMES only — the numbers are nowhere in text — so without this the plot is nothing at all to a screen reader. Falls back to lineChart.label.string | nullnull
valueFormatWrites every number the chart shows: the y-axis ticks and the tooltip values. null uses Intl.NumberFormat in LOCALE_ID, with compact ticks (1.2K, 3.4M) unless the full numbers are shorter.((value: number) => string) | nullnull
xLabelsLabels for the X axis (one per data point).readonly string[][]
heightChart pixel height.number240
showGridShow gridlines + axis ticks.booleantrue
showLegendShow the legend above the chart.booleantrue
showDotsShow dots at each data point.booleantrue
tooltipShow the hover readout: the crosshair, the point markers and the tooltip. Off drops all three, since a crosshair with no values beside it points at nothing.booleantrue

Types

interface WrLineSeries {
  label: string;
  data: readonly number[];
  color?: string;
}
NameDescriptionTypeDefault
WrLineSeriesOne plotted line.interface—
labelrequiredLegend label.string—
datarequiredY values, evenly spaced along the x axis.readonly number[]—
colorCSS color for the stroke.stringpalette

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/charts/line-chart's own element.

VariableDefaultDeclared on
--wr-line-chart-font-familyvar(--wr-font-family-base).wr-line-chart
--wr-line-chart-legend-column-gapvar(--wr-space-lg).wr-line-chart__legend
--wr-line-chart-legend-item-font-sizevar(--wr-text-xs).wr-line-chart__legend-item
--wr-line-chart-legend-item-gapvar(--wr-space-sm).wr-line-chart__legend-item
--wr-line-chart-legend-margin-bottomvar(--wr-space-md).wr-line-chart__legend
--wr-line-chart-legend-row-gapvar(--wr-space-sm).wr-line-chart__legend
--wr-line-chart-plot-inset-xvar(--wr-space-md).wr-line-chart
--wr-line-chart-plot-inset-yvar(--wr-space-sm).wr-line-chart
--wr-line-chart-tick-colorvar(--wr-color-on-surface-muted).wr-line-chart__y-axis
--wr-line-chart-tick-font-sizevar(--wr-text-xs).wr-line-chart__y-axis
--wr-line-chart-tick-gapvar(--wr-space-xs).wr-line-chart__y-axis
--wr-line-chart-tick-line-heightvar(--wr-text-xs-leading).wr-line-chart__y-axis
--wr-line-chart-tooltip-bordervar(--wr-border-base).wr-line-chart__tooltip
--wr-line-chart-tooltip-font-sizevar(--wr-text-xs).wr-line-chart__tooltip
--wr-line-chart-tooltip-label-font-weightvar(--wr-font-weight-semibold).wr-line-chart__tooltip-label
--wr-line-chart-tooltip-label-margin-bottomvar(--wr-space-xs).wr-line-chart__tooltip-label
--wr-line-chart-tooltip-padding-xvar(--wr-space-md).wr-line-chart__tooltip
--wr-line-chart-tooltip-padding-yvar(--wr-space-sm).wr-line-chart__tooltip
--wr-line-chart-tooltip-radiusvar(--wr-border-radius-base).wr-line-chart__tooltip
--wr-line-chart-tooltip-row-gapvar(--wr-space-sm).wr-line-chart__tooltip-row
--wr-line-chart-tooltip-value-font-weightvar(--wr-font-weight-semibold).wr-line-chart__tooltip-value
--wr-line-chart-x-labels-font-sizevar(--wr-text-xs).wr-line-chart__x-labels
--wr-line-chart-x-labels-margin-topvar(--wr-space-xs).wr-line-chart__x-labels

See also