Vanilla Breeze

chart-wc

SVG chart component with progressive enhancement: semantic table → CSS chart → SVG chart. Supports bar, column, line, area, pie, ring, scatter, and bubble types.

Overview

An SVG chart web component with built-in charting engine. Supports eight chart types with five data source options. Progressive enhancement means a semantic <table> is visible without JavaScript — with JS, the SVG chart renders and the table becomes screen-reader only.

Chart Types

Set data-type to one of: bar, column, line, area, pie, ring, scatter, or bubble.

Line Chart

Pie Chart

Pie charts accept a flat object (label → value) as data.

Ring Chart

A ring (donut) chart is a pie with a transparent center hole. Same data shape as pie: a flat object of label → value. Slices below an angular threshold render with external leader-line labels; the percentage labels inside the slices are suppressed in ring mode to keep the chart readable at small sizes.

Tunables specific to ring (and pie) charts — pass via data-config:

PathDefaultPurpose
center.size"40%"Hole diameter as a percent of the chart's viewBox. Larger values produce a thinner ring.
center.style.fillvar(--color-surface, #fff)Hole fill. Follows the active VB theme by default; override with a custom --color-surface or an explicit fill value.
plot.node.label.placement"auto"auto uses external labels for small slices and hides internal labels in ring mode. Force with "outside".
plot.node.label.threshold12Slice angle (degrees) below which auto-placement switches to an external leader-line label.

Sparkline mode

Add data-size="sparkline" to render a minimal trend chart with no axes, gridlines, tick labels, axis labels, title, legend, or tooltip. The chart becomes a pure inline shape sized by its container — ideal for dashboard tiles, data tables, and the sparkline slot of <score-card>.

Sparkline mode is a deterministic opt-in: shrinking the container alone won't strip chrome. Add the attribute when you want a sparkline, omit it for the full chart.

The line, area, and column/bar chart types are the recommended sparkline shapes. pie and ring still render but ignore the chrome-strip (their chrome is the chart). Pair with a CSS custom property override on --chart-series-1 to colour the trend by tone:

Data Sources

The component resolves data using this priority chain:

PrioritySourceDescription
1JS property (.data)Set data programmatically
2data-valuesInline JSON attribute
3<script type="application/json">JSON script block child
4<template data-chart-data>Template child with JSON
5<table>Child table (progressive enhancement)

Table Source (Progressive Enhancement)

Wrap a semantic <table> inside <chart-wc>. The chart extracts data from the table and renders SVG. Without JavaScript, the table remains visible.

Script Block

Template

Table Column Control

Use data-chart-label, data-chart-series, and data-chart-ignore on <th> elements to control how table columns are extracted.

Attributes

AttributeValuesDefaultDescription
data-type"bar", "column", "line", "area", "pie", "scatter", "bubble"Chart type to render
data-valuesstringChart data as JSON string
data-configstringSVC config overrides as JSON string
data-titlestringChart title text
data-legendbooleanShow legend (presence enables)
data-tooltipbooleanEnable tooltips (presence enables)
data-palettestringCustom color palette as JSON array
data-chart"replace", "enhance"How to handle source table: replace hides table, enhance keeps both

Structure

ElementRequiredDescription
<table>yesOptional source table — data is extracted and table becomes screen-reader accessible
<script type='application/json'>yesOptional inline JSON data source
<template data-chart-data>yesOptional template-based JSON data source

Events

EventDetailDescription
chart-wc:render{ type, seriesCount }Fired after SVG chart renders successfully
chart-wc:error{ message }Fired when chart rendering fails

JavaScript API

Property / MethodTypeDescription
.dataArray|ObjectGet/set chart data. Triggers re-render on set.
.configObjectGet/set chart config overrides. Triggers re-render on set.
.refresh()voidRe-extract table data and re-render the chart.
.toSVG()string|nullGet the current SVG markup for export.

Reactive updates (JS-first)

For frameworks pushing live data, wait for chart-wc:upgraded before the first assignment, then react to changes via chart-wc:data-changed. The source field lets consumers ignore echoes from their own assignments.

See the Data API concepts guide for the dual HTML-first / JS-first contract that <chart-wc> shares with <kanban-board>, <work-item>, and <user-story>.

EventDetailWhen
chart-wc:upgradedOnce after first connect; safe signal for the first .data assignment.
chart-wc:data-changed{ data, config, source: 'property' }Fires when .data or .config is assigned via the property API.

Theme Integration

Charts read VB design tokens via CSS custom properties. The theme bridge converts these into palette and axis configuration automatically.

Custom PropertyPurpose
--chart-series-1--chart-series-6Chart color palette per series
--chart-label-colorAxis tick label color
--chart-axis-colorAxis line color
--chart-grid-colorGrid line color

Progressive Enhancement

LayerEnvironmentExperience
1No CSS, no JSPlain semantic table
2CSS onlyCSS chart via .vb-chart class
3CSS + JSFull SVG chart with interactivity

Loading

<chart-wc> is part of the optional charts bundle (main-charts.js), not the core bundle. Include it separately: