Sparkline Chart
PROSummarize numeric trends and changes in a small space.
Usage guide
#Summarize compact trends inside tables or cards. Use Charts for detailed visualizations with axes and legends.
Numeric values
Pass a numeric array to values and choose line, area, column, or pie in type.
Stock data
stock uses an array of objects with open, high, low, and close, rather than a numeric array.
- Meaning and exploration
- Explain the data with
labeland enable exploration withinteractiveandshowTooltip. - Append live values
streampreserves the initial array length. Adding withaddValue()removes the oldest value.
Examples
#Feature examples
#Choose a feature from 32 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.
No matching features.
API reference
#Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.
<sy-sparkline-chart>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
SySparklineValuesInput | [] | Array of numbers or OHLC objects. JSON strings are also accepted. Pass objects and arrays as JavaScript properties. | |
SySparklineChartType | 'line' | Chart type: line, area, column, pie, or stock. | |
number | 160 | Label area width, as a CSS length. | |
number | 40 | Height as a CSS length or a numeric string interpreted as pixels. | |
number | undefined | Minimum allowed value or input length. See the component's usage guide for the unit. | |
number | undefined | Maximum allowed value or input length. | |
boolean | false | Use smooth curves for line and area charts. | |
boolean | false | Show points on the line. | |
boolean | false | Show a summary value alongside the chart. | |
boolean | true | Explore values with the pointer and keyboard. | |
string | 'Sparkline chart' | Label describing the item. | |
string | 'No data' | Empty-state placeholder text shown when `values` has no usable numbers. Spec name: `empty-text`. | |
(value: number, index: number) => string | undefined | Optional formatter for the tooltip / value label. Pass objects and arrays as JavaScript properties. | |
string | '' | Color applied to the component. Check the type for supported values. | |
string | '#000000' | CSS colour for the value label and tooltip text. Spec name: `font-color`. | |
'top' | 'bottom' | 'top' | Where to render the value label relative to the active point. With `auto` (the default) the label flips when there isn't enough room on the chosen side. Spec name: `text-position`. | |
boolean | false | Append new values using a moving window that preserves the initial value count. | |
boolean | true | Animate stream transitions (line/area/column/stock slide left as new values arrive). | |
number | 1000 | Maximum stream animation duration in milliseconds. When values arrive faster than this, the component follows the observed push cadence so the latest value does not lag behind the feed. Spec name: `stream-duration`. | |
boolean | true | Show the tooltip for the active data point. | |
string | '' | Font size for the value label inside the SVG. Accepts any CSS length (e.g. `12px`, `0.85rem`). Spec name: `text-size`. | |
number | 2 | Divider thickness in pixels. | |
string | '' | Reference baseline. Line / area / column compare points against this value and render "above" / "below" colours. Stock draws the same horizontal reference line but keeps its up/down candle colours. Empty or non-numeric values disable the feature. | |
SySparklineStockColorScheme | 'us' | Stock candle colour convention. `us` = up green / down red. `kr` = up red / down blue. Other chart types ignore this prop. Spec name: `stock-color-scheme`. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ index: number; value: number }> | Read the result from the event's detail. | |
CustomEvent<{ index: number; value: number }> | Read the result from the event's detail. | |
CustomEvent<{ index: number; value: number; values: number[] }> | Fires after `addValue()` accepts a value. Detail carries the index it landed at. | |
CustomEvent<{ index: number; value: number; oldValue: number; values: number[] }> | Fires after `updateValue()` replaces a value. Detail carries the old + new value. | |
CustomEvent<{ index: number; value: number; values: number[] }> | Fires after `removeValue()` removes a value. Detail carries the removed value. |
Methods
| Method | Returns | Description |
|---|---|---|
Promise<number[] | SySparklineStockValue[]> | Return the current chart data array. | |
Promise<void> | Activate the specified data point. | |
Promise<void> | Change the OHLC rising/falling color convention to us or kr. | |
Promise<void> | Append a value. In `stream` mode the oldest entry is dropped once the rolling-window cap is reached, and the inner geometry slides one step to the left so the new value appears to push in from the right rather than the existing line wiggling up and down. Non-finite values are ignored. | |
Promise<void> | Replace the value at `index`. Out-of-range indices are silently ignored. Non-finite values are ignored. | |
Promise<void> | Remove the value at `index`. Out-of-range indices are silently ignored. |