chart-wc
SVG chart component powered by SVC. Progressive enhancement: semantic table → CSS chart → SVG chart. Supports bar, column, line, area, pie, scatter, and bubble types.
Overview
An SVG chart web component powered by SVC. 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:
| Priority | Source | Description |
|---|---|---|
| 1 | JS property (.data) | Set data programmatically |
| 2 | data-values | Inline 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
| Attribute | Values | Default | Description |
|---|---|---|---|
data-type |
"bar", "column", "line", "area", "pie", "scatter", "bubble" |
— | Chart type to render |
data-values |
string | — | Chart data as JSON string |
data-config |
string | — | SVC config overrides as JSON string |
data-title |
string | — | Chart title text |
data-legend |
boolean | — | Show legend (presence enables) |
data-tooltip |
boolean | — | Enable tooltips (presence enables) |
data-palette |
string | — | Custom color palette as JSON array |
data-chart |
"replace", "enhance" |
— | How to handle source table: replace hides table, enhance keeps both |
Structure
| Element | Required | Description |
|---|---|---|
<table> |
yes | Optional source table — data is extracted and table becomes screen-reader accessible |
<script type='application/json'> |
yes | Optional inline JSON data source |
<template data-chart-data> |
yes | Optional template-based JSON data source |
Events
| Event | Detail | Description |
|---|---|---|
chart-wc:render |
{ type, seriesCount } |
Fired after SVG chart renders successfully |
chart-wc:error |
{ message } |
Fired when chart rendering fails |
JavaScript API
| Property / Method | Type | Description |
|---|---|---|
.data | Array|Object | Get/set chart data. Triggers re-render on set. |
.config | Object | Get/set SVC config overrides. Triggers re-render on set. |
.refresh() | void | Re-extract table data and re-render the chart. |
.toSVG() | string|null | Get the current SVG markup for export. |
Theme Integration
Charts read VB design tokens via CSS custom properties. The theme bridge converts these into SVC palette and axis configuration automatically.
| Custom Property | Purpose |
|---|---|
--chart-series-1 … --chart-series-6 | Chart color palette per series |
--chart-label-color | Axis tick label color |
--chart-axis-color | Axis line color |
--chart-grid-color | Grid line color |
Progressive Enhancement
| Layer | Environment | Experience |
|---|---|---|
| 1 | No CSS, no JS | Plain semantic table |
| 2 | CSS only | CSS chart via .vb-chart class |
| 3 | CSS + JS | Full SVG chart with interactivity |
Loading
<chart-wc> is part of the optional charts bundle (main-charts.js), not the core bundle. Include it separately: