Skip to content

Sparkline

Last updated 12 Nov 2026

NbSparkline is a tiny inline chart for embedding in dashboard tiles, table cells, and KPI widgets. It renders a single line with an optional gradient fill underneath, with no axes, labels, legend, or tooltip. The SVG uses viewBox with preserveAspectRatio="none" so it stretches to fill its container while the stroke stays visually consistent thanks to vector-effect="non-scaling-stroke".

Color ​

Pass any valid CSS color, including design-system tokens.

vue
<template>
  <NbSparkline :data="series" color="var(--nb-c-success)" />
</template>

Props ​

PropTypeDefaultDescription
datanumber[]requiredValues to plot. Needs at least 2 entries to render.
colorstringvar(--nb-c-primary)Line and gradient color. Any CSS color string.
heightnumber | string40SVG height. Numbers are interpreted as pixels.
widthnumber | string'100%'SVG width. Numbers are interpreted as pixels.
strokeWidthnumber1.5Line thickness in pixels (non-scaling-stroke).
fillbooleantrueRender the gradient area under the line.
smoothbooleantrueUse bezier smoothing between data points.
animatebooleanfalseDraw the line in from the left on first render and on data change.

Entrance animation ​

animate draws the line, and the fill under it, in from the left when the sparkline first renders and again when its data changes. It is off by default and is switched off entirely under prefers-reduced-motion: reduce.

vue
<NbSparkline animate :data="values" />

Notes ​

  • The component renders a fixed internal viewBox of 0 0 100 30 and stretches it via preserveAspectRatio="none" to match the requested width and height. Stroke width stays visually constant because the line uses vector-effect="non-scaling-stroke".
  • The gradient fades from color at 30 % opacity at the top to fully transparent at the bottom.
  • Each instance generates a unique gradient id via Vue's useId(), so multiple sparklines on the same page do not collide.
  • A small vertical padding (~8 % of height) is reserved so the line never touches the top or bottom edge.