Skip to content
prism logoPrismUI
Responsive SVG charts with explicit updates, accessible interactions, and CSS theming.
Version
v3.0.0
Size
12.3 KB gzip
Browser
createLineChartcreateBarChartcreateAreaChartcreatePieChartcreateSparkline View all 18 exports

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',
  },
]);
FeaturePrismChart.jsLightweight ChartsD3
Bundle size12.3 KB~60 kB~45 kB~30 kB (core)
Zero dependencies (Orbit) (modular)
RendererSVGCanvasCanvasSVG/Canvas
Data updatesExplicit update()Instance mutationSeries mutationManual
CSS themeableLimited
Framework-neutral
Accessible SVGManual
TypeScript-firstPartialTypes 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/prism
sh
npm install @vielzeug/prism
sh
yarn add @vielzeug/prism

Quick 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 interpolation
  • createBarChart(container, config) — bar chart with four layout variants: grouped, stacked, grouped-horizontal, stacked-horizontal
  • createAreaChart(container, config) — filled area with configurable opacity
  • createSparkline(container, config) — minimal inline sparkline (line, area, or bar variant)
  • createPieChart(container, config) — pie, donut, or semi-circle donut chart
  • linearScale(config) — continuous numeric scale with nice tick generation
  • timeScale(config) — date/time scale with interval-based ticks
  • bandScale(config) — categorical scale for bar charts
  • ChartHandle.update(data) — replace chart data synchronously without coupling to a state library
  • seriesColor(index, override?) — resolve CSS palette color by series index
  • setTheme(theme) / resetTheme() — apply or clear custom colors, font, and grid tokens at runtime
  • Event hooksonClick and onHover callbacks on every chart
  • DevtoolsdebugChart() from @vielzeug/prism/devtools logs mount/resize/dispose to console.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

ImportPurpose
@vielzeug/prismAll chart factories, scales, and types
@vielzeug/prism/themeDefault CSS (custom properties + dark mode)
@vielzeug/prism/devtoolsdebugChart() — opt-in console.debug lifecycle logging, tree-shaken in production

Documentation

See Also

  • Refine — accessible web components that pair well with Prism for dashboards
  • Orbit — floating element positioning for chart tooltips and popovers