Vanilla Breeze

chart-wc

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

Overview

An SVG chart web component with built-in charting engine. Supports seven 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, scatter, or bubble.

Line Chart

Pie Chart

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

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.

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: