Charts
VdChart renders bar, line, area, scatter, donut, and pie charts. Supply data and field names. Each chart includes labelled marks, keyboard navigation, tooltips, and an optional data table.
Keyboard navigation and data table
Show the data table with data-table="visible". Production default is true (sr-only, for assistive tech only); false suppresses it.
Core Chart Types
Bar, line, area, scatter, donut, and pie — automatic dimension measurement and responsive resize. Click a donut or pie slice to see @slice-click.
Bar Chart
Line Chart
Area Chart
Donut Chart
Custom centerLabel string
centerLabel: true shows the computed total
Pie Chart
Data Accuracy & Advanced Features
Handles mixed positive and negative values from zero baseline, multi-series grouped bars with legends, reference line annotations, and 2D scatter plots.
Profit & Loss (Negative Y-values)
Multi-Series Grouped Bar (right legend)
Annotations & Pinned Range
Scatter Plot (2D Coordinates)
Data Labels & Stage Colors
Accessibility
Give the chart a title and a description of the takeaway. Marks expose value labels; the generated table exposes the data through standard table navigation. Test your labels, colors, and interactions with your users’ assistive technology.
Graphics roles and a data table are features, not a claim of WCAG conformance for the finished page.
API & Keyboard Reference
Installation
Accessible Chart Usage
<!-- WAI-ARIA Graphics, keyboard navigation, and data table fallback -->
<script setup lang="ts">
import { VdChart, type ClickEvent } from '@vanduo-oss/vd3-charts';
import '@vanduo-oss/vd3-charts/css';
const data = [
{ quarter: 'Q1', revenue: 145 },
{ quarter: 'Q2', revenue: 210 },
{ quarter: 'Q3', revenue: 185 },
{ quarter: 'Q4', revenue: 290 },
];
const onClick = (e: ClickEvent) => console.log('Clicked:', e.datum);
</script>
<template>
<!-- data-table default is true (sr-only). Use "visible" to show the
data table in layout, or false to suppress it. -->
<VdChart
type="bar"
:data="data"
x="quarter"
y="revenue"
title="Quarterly Revenue"
data-table="visible"
@bar-click="onClick"
/>
</template>Advanced Features Usage
Keyboard Navigation Shortcuts
| Key | Behavior |
|---|---|
| Tab / Shift+Tab | Enter or leave the interactive chart mark group. |
| ArrowRight / ArrowDown | Move focus to the next data mark (cycles with wraparound) and displays its tooltip. |
| ArrowLeft / ArrowUp | Move focus to the previous data mark (cycles with wraparound) and displays its tooltip. |
| Home | Jump keyboard focus directly to the first data mark. |
| End | Jump keyboard focus directly to the last data mark. |
| Enter / Space | Trigger the mark's click callback (e.g. @bar-click, @point-click, @slice-click). |
| Escape | Blur the focused mark and dismiss the active tooltip. |
Chart Types
| Type | Description |
|---|---|
type="bar" / VdBarChart | Category bars with band scale, axes, grid lines, negative y handling, keyboard arrow navigation, and data table fallback. |
type="line" / VdLineChart | Line path with interactive circle marks over category, numeric, or date-like x values. |
type="area" / VdAreaChart | Filled area path closing to zero baseline plus line path, sharing the cartesian scale engine. |
type="scatter" / VdScatterChart | Circle marks over 2D numeric, date-like, or categorical scales with point click handling. |
type="donut" / VdDonutChart | Arc slices with inner-radius ratio (default 0.62), percentage tooltips, center total summary (or custom centerLabel / centerSubLabel), and legend. |
type="pie" / VdPieChart | Solid pie wedges. Both VdChart type="pie" and VdPieChart default to an inner-radius ratio of 0. |
Component API (Props & Events)
| Prop / Event | Description |
|---|---|
:type | 'bar' | 'line' | 'area' | 'scatter' | 'donut' | 'pie' (default 'bar'). Or import typed VdBarChart, VdLineChart, VdAreaChart, VdScatterChart, VdDonutChart, VdPieChart. |
:data | Array of row objects. |
x / y | Cartesian accessors — field key string or (datum) => value function. |
label / value | Pie / donut accessors. |
refresh() (template ref) | Charts observe data-theme, data-primary, data-palette, data-neutral, class, and style mutations automatically. Call refresh() for imperative redraws. |
title / description / :aria-label | Rendered into SVG accessibility metadata (<title>, <desc>, and aria-label). |
:data-table | true (sr-only, default) | 'visible' | false. Generates an HTML data table. |
:inner-radius-ratio | Hole size (0–0.9): donut defaults to 0.62; pie defaults to 0. |
:center-label / :center-sub-label | Custom center text and subtitle inside a donut hole (or :center-label="false" to hide). |
:aria-role-description | Custom ARIA role description override for the SVG shell (defaults to `${type} chart`). |
:svg-role | Override the inner SVG graphics role. The standard role attribute still falls through to the wrapper root; core factories use the role option directly. |
:width / :height / :margin | Explicit SVG width, container min-height in px (default 300), and plot margin override ({ top, right, bottom, left } or number). |
:theme / :tooltip / :responsive | Theme overrides, custom/disabled tooltip, responsive resize observer. |
:series | Multiple series — grouped bars, or one line/area path each (Series[]). |
:color | A CSS color string ('#40c057', 'rgb(...)', 'var(...)'), category-field name, or per-datum (row) => color callback across Cartesian and polar charts. |
:stroke / :stroke-width / :fill / :fill-opacity | Line and area mark styling overrides (stroke color, stroke width, area fill color/boolean, and area opacity). |
:points / :point-radius / :point-fill / :point-opacity | Point mark visibility (false hides line/area points), radius in px, fill color, and scatter point opacity. |
:bar-padding / :x-scale | Bar band padding (0–0.8, default 0.18) and horizontal scale type ('band' | 'point' | 'linear' | 'time'). |
:data-labels | true or { format, color } — draw value labels on each mark. |
:annotations | Reference lines: [{ y?, x?, label?, color?, dash? }]. |
:x-min / :x-max / :y-min / :y-max / :y-tick-count / :y-include-zero | Pin axis bounds and tick density (supports negative floors and clamped baselines). |
:x-format / :y-format / :x-axis / :y-axis | Custom tick formatters and axis titles ({ label }). |
:legend | true, false, or { position: 'top' | 'right' } — shown by default for multi-series and polar charts. |
@bar-click / @point-click / @slice-click | Mark-click events — each carries ClickEvent { event, datum, index }. |