Version v3.0.0 Size 12.3 KB gzip
Why Prism?
Charting libraries typically require a framework binding, bundle heavy dependencies, or force canvas rendering that can't be styled with CSS. Prism takes a different approach:
ts
// Before — Chart.js, imperative setup with a canvas you can't CSS-theme
import Chart from 'chart.js/auto';
const ctx = document.getElementById('myChart') as HTMLCanvasElement;
new Chart(ctx, {
type: 'line',
data: { labels, datasets: [{ data: values }] },
// re-create or mutate the Chart.js instance when data changes
});
// After — Prism, responsive SVG with an explicit update boundary
import { createLineChart } from '@vielzeug/prism';
const chart = createLineChart(document.getElementById('chart')!, {
a11y: { ariaLabel: 'Users by day' },
series: [
{
data: [
{ key: 1, value: 12 },
{ key: 2, value: 40 },
{ key: 3, value: 28 },
],
name: 'Users',
},
],
tooltip: true,
});
chart.update([
{
data: [
{ key: 1, value: 12 },
{ key: 2, value: 40 },
{ key: 3, value: 28 },
{ key: 4, value: 65 },
],
name: 'Users',
},
]);| Feature | Prism | Chart.js | Lightweight Charts | D3 |
|---|---|---|---|---|
| Bundle size | 12.3 KB | ~60 kB | ~45 kB | ~30 kB (core) |
| Zero dependencies | ||||
| Renderer | SVG | Canvas | Canvas | SVG/Canvas |
| Data updates | Explicit update() | Instance mutation | Series mutation | Manual |
| CSS themeable | Limited | |||
| Framework-neutral | ||||
| Accessible SVG | Manual | |||
| TypeScript-first | Partial | Types available |
Use Prism when you need lightweight, framework-neutral charts with explicit updates and SVG output that can be styled with CSS. It fits dashboards, admin panels, and data-heavy applications.
Consider alternatives when you need 50+ chart types (ECharts), financial trading charts (Lightweight Charts), or low-level visualization grammar (D3).
Installation
sh
pnpm add @vielzeug/prismsh
npm install @vielzeug/prismsh
yarn add @vielzeug/prismQuick Start
ts
import { createLineChart } from '@vielzeug/prism';
import '@vielzeug/prism/theme';
const chart = createLineChart(document.getElementById('chart')!, {
a11y: { ariaLabel: 'Revenue by month' },
series: [
{
color: '#3b82f6',
data: [
{ key: 1, value: 10 },
{ key: 2, value: 25 },
{ key: 3, value: 18 },
{ key: 4, value: 32 },
],
name: 'Revenue',
},
],
xAxis: { position: 'bottom' },
yAxis: { position: 'left', grid: true },
tooltip: true,
crosshair: true,
onHover: (event) => console.log(event?.datum),
});
// Update chart data explicitly
chart.update([
{
color: '#3b82f6',
data: [{ key: 1, value: 10 }, { key: 2, value: 25 }, { key: 3, value: 18 }, { key: 4, value: 32 }, { key: 5, value: 28 }],
name: 'Revenue',
},
]);
// Cleanup when done
chart.dispose();Features
createLineChart(container, config)— line chart with linear, monotone, or step interpolationcreateBarChart(container, config)— bar chart with four layout variants: grouped, stacked, grouped-horizontal, stacked-horizontalcreateAreaChart(container, config)— filled area with configurable opacitycreateSparkline(container, config)— minimal inline sparkline (line, area, or bar variant)createPieChart(container, config)— pie, donut, or semi-circle donut chartlinearScale(config)— continuous numeric scale with nice tick generationtimeScale(config)— date/time scale with interval-based ticksbandScale(config)— categorical scale for bar chartsChartHandle.update(data)— replace chart data synchronously without coupling to a state libraryseriesColor(index, override?)— resolve CSS palette color by series indexsetTheme(theme)/resetTheme()— apply or clear custom colors, font, and grid tokens at runtime- Event hooks —
onClickandonHovercallbacks on every chart - Devtools —
debugChart()from@vielzeug/prism/devtoolslogs mount/resize/dispose toconsole.debug; tree-shaken from production unless imported - CSS custom properties — full theme control via
--prism-*tokens - Responsive — auto-resizes via
ResizeObserver - Accessible — ARIA labels and semantic SVG structure
Symbol.dispose— explicit resource management following TC39 proposal
Sub-paths
| Import | Purpose |
|---|---|
@vielzeug/prism | All chart factories, scales, and types |
@vielzeug/prism/theme | Default CSS (custom properties + dark mode) |
@vielzeug/prism/devtools | debugChart() — opt-in console.debug lifecycle logging, tree-shaken in production |