<sv-chart> reference
Every property, attribute and event of the chart custom element.
This page is generated from SvChart's own props type by
packages/grid-wc/scripts/generate-surface.mjs, the same way the
<sv-grid> reference is, and CI fails if it drifts.
Loading it
<script type="module" src="https://cdn.jsdelivr.net/npm/@svgrid/grid-wc/dist/chart/sv-chart-element.js"></script>
<sv-chart id="chart" legend="right" zoomable range-presets></sv-chart>
<script type="module">
const chart = document.getElementById('chart')
chart.spec = { // property: an object
type: 'line',
categories: ['2026-01-01', '2026-01-02', '2026-01-03'],
series: [{ label: 'Close', values: [10, 12, 11] }],
xType: 'ordinal-time',
}
chart.addEventListener('select', (e) => console.log(e.detail)) // { category, series, value }
chart.addEventListener('zoom', (e) => console.log(e.detail)) // { i0, i1 } or null
</script>
From npm, import '@svgrid/grid-wc/chart' registers the element; the React
and Vue wrappers are @svgrid/grid-wc/react/chart and
@svgrid/grid-wc/vue/chart, and the Angular package exports SvChartComponent
next to SvGridComponent.
Attributes vs properties
The same rule as the grid element:
primitives are attributes, arrays / objects / functions are properties.
spec is always a property. A prop that takes a boolean OR a string, like
legend (true, or a side), keeps a string attribute: legend alone means
true, legend="right" puts the legend on the right, legend="false" hides it.
The bindable props (zoom, selected, drill-path, and the drawings) are
written back onto the element after their event, so chart.zoom reads the
current window inside or after a zoom listener.
Attributes (26)
Primitives, so they work in plain HTML as well as through a property.
| Attribute | Property | Type |
|---|---|---|
legend |
legend |
boolean | ChartLegendPosition |
interactive |
interactive |
boolean |
data-labels |
dataLabels |
boolean | ChartDataLabelConfig |
tooltip-mode |
tooltipMode |
'shared' | 'single' |
tooltip-position |
tooltipPosition |
'follow' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' |
tooltip-sticky |
tooltipSticky |
boolean |
zoomable |
zoomable |
boolean | ChartZoomConfig |
range-presets |
rangePresets |
boolean | ChartRangePreset[] |
sync-group |
syncGroup |
string |
context-menu |
contextMenu |
boolean | MenuItem[] | ((target: ChartContextTarget) => MenuItem[]) |
animate |
animate |
boolean | ChartAnimateConfig |
live |
live |
boolean |
drillable |
drillable |
boolean |
selectable |
selectable |
boolean | 'single' | 'multi' |
hover-highlight |
hoverHighlight |
boolean |
announce |
announce |
boolean |
describe |
describe |
boolean |
crosshair-labels |
crosshairLabels |
boolean |
brush |
brush |
boolean |
brush-height |
brushHeight |
number |
toolbar |
toolbar |
boolean |
width |
width |
number |
height |
height |
number |
autosize |
autosize |
boolean |
annotatable |
annotatable |
boolean |
drawable |
drawable |
boolean | ChartDrawingKind[] |
Properties only (7)
Arrays, objects and functions. An HTML attribute is a string, so these can
only be assigned in script: el.columns = [...].
| Property | Type |
|---|---|
spec |
ChartSpec |
formatValue |
(value: number) => string |
tooltipFormat |
(ctx: ChartTooltipContext) => { ... } |
zoom |
ChartZoomWindow | null |
drillPath |
string[] |
selected |
ChartPointRef[] |
localeText |
Partial<ChartMessages> |
Events (8)
detail is the callback's argument. The one callback that takes two carries
an object keyed by its parameter names.
| Event | From | detail |
|---|---|---|
select |
onSelect |
selection |
drill |
onDrill |
selection |
zoom |
onZoom |
window |
selectionchange |
onSelectionChange |
selected |
hover |
onHover |
point |
annotate |
onAnnotate |
void |
annotationremove |
onAnnotationRemove |
index |
drawingschange |
onDrawingsChange |
drawings |
Not exposed (4)
| Prop | Why |
|---|---|
legendItem |
Svelte snippet - cannot cross the custom-element boundary |
tooltip |
Svelte snippet - cannot cross the custom-element boundary; use tooltipFormat |
underlay |
Svelte snippet - cannot cross the custom-element boundary |
overlay |
Svelte snippet - cannot cross the custom-element boundary |
What it renders
The element is the Svelte chart component with a DOM surface, so everything
the component draws, the element draws from the same spec: every chart type,
synchronized charts with the zoom gestures and the context menu, and the
financial toolkit with its indicator panes and drawing tools. These three
demos are that component; give <sv-chart> their specs and the picture is
the same.
Where the spec comes from
The element takes the same ChartSpec the Svelte component does. Build it by
hand, or with the helpers exported from @svgrid/grid: rowsToChartSpec
for a grouped chart from rows, rowsToOhlcSpec for candlesticks,
indicatorPane for an RSI / MACD / volume pane. The
charts guide covers every field.
Live examples
- Every chart type - Every chart type from one dataset, thirty live thumbnails: bar, horizontal bar, line, area, lollipop, dumbbell, range bar, range area, pareto, radial column, radial bar, nightingale, pie / donut, tree map, sunburst, funnel, waterfall, sankey, chord, radar, heat map, scatter, box plot, histogram, gauge, bullet, calendar, stream, candlestick and OHLC. Click a card for the full-size chart and its variants: classic / hollow / Heikin-Ashi candles, funnel / pyramid / cone, wiggle / silhouette streams, stacking. Every spec is built with the helpers the grid chart panel uses.
- Synchronized charts with zoom, pan and presets - Two years of daily prices and volumes as two charts that move as one: hover either for a shared crosshair, Ctrl + wheel or pinch to zoom around the pointer, Shift + drag or the hand button to pan, 1W / 1M / 3M / 6M / YTD / 1Y / All presets, and a grid that shows exactly the rows in the window. Right-click for a context menu with export, zoom and series items plus your own. Below: bars that grow in and slide on every data change with multi-selection, and a sunburst that drills down on click with a breadcrumb back up.
- Financial workbench - A year of daily prices as a trading terminal, free in the grid package: rows to candles with rowsToOhlcSpec, a daily / weekly toggle through resampleOhlc, Bollinger bands or an EMA on the price, volume, RSI, MACD, stochastic, ATR and OBV panes stacked under it with one x axis and one crosshair, a last-price pill, earnings and dividend flags with tooltips, drawing tools (trend line, ray, Fibonacci, rectangle, arrow, note) stored as data points, range presets, Ctrl + wheel zoom, PDF and print. Below, the same rows in the grid panel with Candlestick picked, indicator chips, the chart builder and the link toggle.
Related articles
- SvGrid Cheat Sheet - The One-Page Quick Reference - Dense copy-paste reference for @svgrid/grid - install, column shapes, features, the imperative API, server-side data, custom cells, and theming tokens on one page.