lunaDOM Docs
lunaDOM Docs

lunaDOM is a collection of lightweight, accessible shadowdom based web components built with JavaScript.

v0.0.25

The <luna-sparkline> component displays inline charts for visualizing trends with multiple appearance modes and curve types.

Paths

/lunadom/components/sparkline/sparkline.js REQUIRED

Basic Usage

Appearances

Trend Colors

Curve Types

With Data Points

Custom Colors & Sizes

Inline Text Usage

Our API response times have improved by 15% this week.

Customization

Attributes
data - Space-separated numeric values to visualize. Minimum 2 values required.
label - Descriptive label for accessibility (not visible, announced by screen readers).
appearance - How the sparkline fills. Defaults to 'solid'.
trend - Color theme based on data trend. Defaults to 'neutral'.
curve - How data points connect. Defaults to 'linear'.
size - The size of the sparkline. Defaults to 'md'.
color - Custom color for the sparkline (overrides trend colors).
show-dots - If present, shows dots at each data point.
show-area - If present, fills the area under the line.
min - Minimum value for the Y-axis scale. If not set, uses data minimum.
max - Maximum value for the Y-axis scale. If not set, uses data maximum.

CSS Variables
--luna-sparkline-width - The width of the sparkline. Defaults to 100px.
--luna-sparkline-height - The height of the sparkline. Defaults to 32px.
--luna-sparkline-color - The color of the sparkline stroke and fill.
--luna-sparkline-stroke-width - The width of the sparkline stroke.
--luna-sparkline-opacity - The opacity of the filled area.

Events
luna-sparkline-render - Emitted when the sparkline is rendered.
{ data: number[], min: number, max: number }

Example Code

<!-- Basic Sparkline --> <luna-sparkline data="5 10 8 15 12 18 20" label="Sales trend" > </luna-sparkline> <!-- Appearances --> <luna-sparkline data="5 10 8 15 12 18 20" appearance="solid" > </luna-sparkline> <luna-sparkline data="5 10 8 15 12 18 20" appearance="gradient" > </luna-sparkline> <luna-sparkline data="5 10 8 15 12 18 20" appearance="line" > </luna-sparkline> <!-- Trend Colors --> <luna-sparkline data="5 8 10 15 18 22 25" trend="positive" > </luna-sparkline> <luna-sparkline data="10 12 11 13 12 14 13" trend="neutral" > </luna-sparkline> <luna-sparkline data="25 22 18 15 10 8 5" trend="negative" > </luna-sparkline> <!-- Curve Types --> <luna-sparkline data="5 15 8 20 12 18 25" curve="linear" > </luna-sparkline> <luna-sparkline data="5 15 8 20 12 18 25" curve="natural" > </luna-sparkline> <luna-sparkline data="5 15 8 20 12 18 25" curve="step" > </luna-sparkline> <!-- Sizes & Custom Colors --> <luna-sparkline data="5 10 8 15 12 18 20" size="sm" > </luna-sparkline> <luna-sparkline data="5 10 8 15 12 18 20" color="#3b82f6" > </luna-sparkline> <!-- With Data Points --> <luna-sparkline data="5 10 8 15 12 18 20" show-dots > </luna-sparkline> <luna-sparkline data="5 10 8 15 12 18 20" show-dots show-area > </luna-sparkline> <!-- Inline Text Usage --> <p> API response times <luna-sparkline data="120 115 118 110 108 105 102" trend="positive" size="sm" > </luna-sparkline> have improved by 15%. </p>