Data Visualisation
Vue Sparkline Component
<DomSparkline>Compact trends for metric cards, table cells, and resource lists.
Trends inside a revenue table
| Plan | Revenue | Seven-week trend |
|---|---|---|
| Starter | £7,000 | Starter revenue trend |
| Growth | £17,200 | Growth revenue trend |
| Scale | £21,600 | Scale revenue trend |
Install
npm install @getdom/studiovue
<script setup>
import '@getdom/studio/style.css';
import { DomSparkline } from '@getdom/studio';
const products = [
{ name: 'Starter', revenue: '£7,000', values: [4, 8, 6, 9, 7, 12, 14] },
{ name: 'Growth', revenue: '£17,200', values: [12, 10, 15, 12, 16, 18, 22] },
{ name: 'Scale', revenue: '£21,600', values: [8, 12, 9, 14, 20, 19, 25] },
];
/** Projects weekly measurements into the same record format used by full-size charts. */
function trendRows(values) { return values.map((value, index) => ({ week: `Week ${index + 1}`, value })); }
</script>
<template>
<div class="w-full overflow-auto">
<table class="w-full text-left text-sm"><caption class="sr-only">Revenue and seven-week trends by plan</caption>
<thead class="text-xs text-muted-fg"><tr><th scope="col" class="py-3">Plan</th><th scope="col" class="py-3 text-right">Revenue</th><th scope="col" class="py-3 pl-6">Seven-week trend</th></tr></thead>
<tbody><tr v-for="product in products" :key="product.name" class="border-t border-border"><th scope="row" class="py-4 font-medium">{{ product.name }}</th><td class="py-4 text-right tabular-nums">{{ product.revenue }}</td><td class="w-40 py-4 pl-6"><DomSparkline tooltip :title="`${product.name} revenue trend`" :rows="trendRows(product.values)" x-key="week" :series="[{ key: 'value', color: 'chart-2' }]" /></td></tr></tbody>
</table>
</div>
</template>
Working with your data
The compact chart hides its heading visually, but retains an accessible name and keyboard inspection. Provide a meaningful title when embedding it in a card or table. Enable showTable when a standalone data alternative is needed.
Add tooltip to show the current label and formatted values on hover or keyboard inspection. Tooltips float outside the compact plot, including inside scrolling tables. They are off by default.
Reference
Props
Control props
| Name | Type | TS | Default | Description |
|---|---|---|---|---|
rows | array | Array<unknown> | [] | Application-owned records. Missing measurements remain gaps; zero is valid. |
series | array | Array<unknown> | [] | Field keys or { key, label, color, dashed } definitions. Keep keys stable when filtering. |
xKey | string | string | 'date' | Record field used for category or horizontal axis values. |
xType | 'category' | 'time' | 'number' | string | 'category' | Category preserves row order; time and number use proportional, sorted coordinates. |
title | string | string | 'Trend' | — |
description | string | string | '' | Supporting context, units, or reporting period. |
height | number | number | 48 | — |
format | 'number' | 'compact' | 'currency' | 'percent' | string | 'number' | Value format. Percent expects fractions, such as 0.25 for 25%. |
currency | string | string | 'GBP' | ISO currency code for currency formatting. |
locale | string | string | 'en-GB' | Locale used for number and date labels. |
valueFormatter | function | Function | — | Optional (value) => string override shared by axes, tooltips, and tables. |
xFormatter | function | Function | — | Optional (value) => string override for category/date labels. |
yFormatter | function | Function | — | Optional (value) => string for value-axis ticks only. Tooltips and tables keep the full valueFormatter output. |
loading | boolean | boolean | false | Show a loading state in the reserved plot space. |
error | string | string | '' | Show an application-owned error with a retry action. |
emptyLabel | string | string | 'No data for this period' | Message when no finite measurements are available. |
legend | boolean | boolean | false | — |
showTable | boolean | boolean | false | — |
grid | boolean | boolean | true | Show subtle value-axis grid lines. |
curve | 'linear' | 'monotoneX' | 'step' | string | 'linear' | Line interpolation. Linear avoids implying unobserved smooth changes. |
tooltip | boolean | boolean | false | Show formatted values on hover or keyboard inspection in a floating tooltip outside the compact plot. |
Auto-generated from Sparkline.props and inline _edit hints.
Events
| Name | Payload | Description |
|---|---|---|
| @select | { row, index } | Original application record selected by click or Enter. |
| @retry | — | Requests another attempt to load application data. |
Names auto-detected from defineEmits and source emit() calls; payload and description from __doc.events when present.
Keyboard
- Arrow keys / Home / EndInspect data points.
- EnterSelect the inspected record.