View as Markdown

API reference: @salmonui/charts/sparkline

Sparklinecomponent

import { Sparkline } from '@salmonui/charts/sparkline';
function Sparkline(props: SparklineProps): ReactNode;

Props: SparklineProps

Sparkline props (31)
NameSignatureDescription
datareadonly data: readonly unknown[];

Numbers, or records read through xField / yField.

xFieldoptionalreadonly xField?: string | undefined;
yFieldoptionalreadonly yField?: string | undefined;
scaleoptionalreadonly scale?: 'linear' | 'category' | 'time' | undefined;

How x values are read: data index / category order (linear without xField, category) or epoch ms (time).

typeoptionalreadonly type?: SparklineType | undefined;
widthoptionalreadonly width?: number | undefined;

Drawing size in px; the SVG scales to its box through viewBox. Default 100 x 24.

heightoptionalreadonly height?: number | undefined;
coloroptionalreadonly color?: string | undefined;

Series data color. Default the primary seed.

paletteoptionalreadonly palette?: readonly string[] | undefined;

Data colors for column and win-loss bars, by index.

tieColoroptionalreadonly tieColor?: string | undefined;

Win-loss tie color (data color).

highlightsoptionalreadonly highlights?: Partial<Record<SparklinePointKind, SparklineHighlight>> | undefined;
markersoptionalreadonly markers?: 'all' | readonly SparklinePointKind[] | undefined;
labelsoptionalreadonly labels?: 'all' | readonly SparklinePointKind[] | undefined;
formatoptionalreadonly format?: Intl.NumberFormatOptions | ((value: number) => string) | undefined;

Label and tooltip number format.

localeoptionalreadonly locale?: string | undefined;
bandsoptionalreadonly bands?: readonly SparklineBand[] | undefined;
domainoptionalreadonly domain?: { readonly x?: readonly [ number, number ] | undefined; readonly y?: readonly [ number, number ] | undefined; } | undefined;
baselineoptionalreadonly baseline?: number | undefined;

Value of the axis line (and the column / area base). Default 0 when the data crosses it, else none.

paddingoptionalreadonly padding?: 'none' | 'normal' | 'additional' | undefined;

Range padding around the y extent. Default normal (half a marker).

tooltipoptionalreadonly tooltip?: boolean | SparklineTooltipOptions | undefined;
getPointStyleoptionalreadonly getPointStyle?: ((point: SparklinePoint) => SparklinePointStyle | undefined) | undefined;
onPointClickoptionalreadonly onPointClick?: ((event: SparklinePointEvent) => void) | undefined;
onPointHoveroptionalreadonly onPointHover?: ((event: SparklinePointEvent | null) => void) | undefined;
animatedoptionalreadonly animated?: boolean | undefined;

Entrance transition, default true: set on commit (never in server markup), off under prefers-reduced-motion; the CSS is the opt-in @salmonui/charts/viz-animations.css.

rendereroptionalreadonly renderer?: 'svg' | 'canvas' | 'auto' | undefined;

Mark renderer, default 'svg'. 'canvas' draws the line, area, bars and markers on a canvas (bands, the axis line and labels stay SVG); 'auto' switches at 20,000 points. Canvas needs canvasRenderer, else the marks stay SVG.

canvasRendereroptionalreadonly canvasRenderer?: SparklineCanvasRenderer | undefined;

The canvas mark layer: sparklineCanvas from @salmonui/charts/sparkline/canvas (opt-in, so /sparkline stays small).

labeloptionalreadonly label?: string | undefined;

Accessible name; default the automatic summary.

classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
refoptionalreadonly ref?: Ref<SVGSVGElement> | undefined;

The root <svg>.

idoptionalreadonly id?: string | undefined;