Sparkline Chart

PRO

Summarize numeric trends and changes in a small space.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-sparkline-chart
  width="260"
  height="80"
  aria-label="Completed work over the last 8 days"
  font-color="currentColor"
  type="line"
  show-points
  interactive
  show-tooltip
  thickness="2"
  id="sample"
></sy-sparkline-chart>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "values": [
      12,
      18,
      14,
      26,
      22,
      30,
      27,
      36
    ]
  });
</script>

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 label and enable exploration with interactive and showTooltip.
Append live values
stream preserves the initial array length. Adding with addValue() removes the oldest value.

Feature examples

#

Choose a feature from 32 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Baseline

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Color

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Empty Text

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Font Color

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Font Size

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Height

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Interactive

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Label

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Max

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Min

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Show Points

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Show Tooltip

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Show Value

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Smooth

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Stream

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Text Position

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Thickness

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Type

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Values

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Width

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · addValue

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · getValues

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · removeValue

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · setActiveIndex

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · updateValue

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · Point Focused

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Point Selected

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Value Added

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Value Removed

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Value Updated

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Usage examples · Fixed value range

Keep the vertical range from 0 to 100 and display the latest value.

View code
HTML
<sy-sparkline-chart
  width="260"
  height="80"
  aria-label="Completed work over the last 8 days"
  font-color="currentColor"
  type="line"
  show-value
  interactive
  show-tooltip
  thickness="2"
  min="0"
  max="100"
  id="sample"
></sy-sparkline-chart>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "values": [
      12,
      18,
      14,
      26,
      22,
      30,
      27,
      36
    ]
  });
  const component2 = document.querySelector("#sample");
  Object.assign(component2, {
    "type": "line",
    "min": 0,
    "max": 100,
    "showPoints": false,
    "showValue": true
  });
</script>

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 / PropertyTypeDefaultDescription
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.
number160Label area width, as a CSS length.
number40Height as a CSS length or a numeric string interpreted as pixels.
numberundefinedMinimum allowed value or input length. See the component's usage guide for the unit.
numberundefinedMaximum allowed value or input length.
booleanfalseUse smooth curves for line and area charts.
booleanfalseShow points on the line.
booleanfalseShow a summary value alongside the chart.
booleantrueExplore 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) => stringundefinedOptional 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`.
booleanfalseAppend new values using a moving window that preserves the initial value count.
booleantrueAnimate stream transitions (line/area/column/stock slide left as new values arrive).
number1000Maximum 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`.
booleantrueShow 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`.
number2Divider 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

EventDetailDescription
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

MethodReturnsDescription
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.