ComponentUpdated in v15

Sparkline

A small trend line with no axes, to sit beside a number.

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 { WrSparkline } from 'ngwr/charts/sparkline';

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

Basic

<wr-sparkline [data]="[12, 14, 9, 17, 21, 18, 23]" />

Filled area

Set [showArea] to fill under the line.

<wr-sparkline [data]="data" [showArea]="true" color="var(--wr-color-success)" />

Tooltip

Set [tooltip]="false" to turn it off.

<wr-sparkline [data]="data" ariaLabel="Signups" />
<wr-sparkline [data]="data" ariaLabel="Signups" [tooltip]="false" />

On (default)

[tooltip]="false"

API

NameDescriptionTypeDefault
dataThe values, left to right. Evenly spaced — a sparkline carries no x axis, so pass an already-ordered series rather than points with their own timestamps.readonly number[][]
ariaLabelAccessible name. A sparkline usually sits beside the number it summarises, where announcing it again is noise — so it is aria-hidden by default and becomes a named role="img" only when a consumer says what it shows.string | nullnull
colorStroke colour.string`var(--wr-color-primary)`
strokeWidthLine thickness in CSS pixels — vector-effect="non-scaling-stroke" keeps it at that width whatever the box is stretched to, so it is NOT in viewBox units.number1.5
showAreaFill the area below the line.booleanfalse
showTipShow a dot at the last data point.booleantrue
widthCSS width.string'8rem'
heightCSS height.string'2rem'
tooltipShow a tooltip with the value of the point nearest the pointer, marking that point, and named by ariaLabel when one is given. Pointer only.booleantrue
valueFormatWrites the value in the tooltip. null uses Intl.NumberFormat in LOCALE_ID.((value: number) => string) | nullnull

Dependencies

Built onPopover

See also