DS0
Patterns

Chart

Zero-dependency SVG data visualization with line, bar, area, donut, scatter, and sparkline chart types — all interactive and accessible.

Interactive Playground

Switch between chart types and toggle features to explore every capability. Each chart is rendered as pure SVG with zero external dependencies.

Chart Type
Feature Toggles6 / 6 enabled
Monthly Revenue Trends
Monthly Revenue Trends
CategoryRevenueCostsProfit
Jan4,0002,8001,500
Feb5,8352,8102,868
Mar6,7992,5902,811
Apr6,5512,2681,719
May5,4832,0101,305
Jun4,4861,9582,415
Jul4,4082,1833,952
Aug5,5372,6584,276
Sep7,4333,2703,291
Oct9,1873,8582,573
Nov9,9794,2683,356
Dec9,5704,4104,960

Usage

import { Chart } from '@/recipes/chart';

<Chart
  type="line"
  series={[
    {
      name: 'Revenue',
      data: [
        { x: 'Jan', y: 4000 },
        { x: 'Feb', y: 5200 },
        { x: 'Mar', y: 4800 },
        { x: 'Apr', y: 6100 },
      ],
    },
  ]}
  title="Monthly Revenue"
  height={300}
/>

Chart Types

TypeUse CaseKey Props
lineTrends over timeseries, curve, showPoints
barCategorical comparisonseries, stacked, horizontal
areaVolume over timeseries, stacked, curve
donutPart-to-wholesegments, centerValue, centerLabel
scatterCorrelationseries (numeric x/y)
sparklineInline micro-trendseries, height, width

Donut Chart

<Chart
  type="donut"
  segments={[
    { label: 'Desktop', value: 54.8 },
    { label: 'Mobile', value: 32.1 },
    { label: 'Tablet', value: 8.4 },
  ]}
  centerValue="95.3%"
  centerLabel="Total"
  height={280}
/>

Sparkline

Sparklines are designed for inline use inside table cells, stat cards, or text.

<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
  <span>Revenue</span>
  <Chart
    type="sparkline"
    series={[{ name: 'Rev', data: [4, 7, 5, 9, 6, 8, 12].map((y, i) => ({ x: i, y })) }]}
    height={32}
    width={120}
    legend={false}
    tooltip={false}
    grid={false}
  />
  <strong>$12.4k</strong>
</div>

API Reference

PropTypeDefaultDescription
type'line' | 'bar' | 'area' | 'donut' | 'scatter' | 'sparkline'Chart type
seriesChartSeries[][]Data series for line/bar/area/scatter/sparkline
segmentsDonutSegment[][]Segments for donut chart
widthnumberautoChart width (auto-resizes)
heightnumber300Chart height
titlestringChart title
xLabelstringX-axis label
yLabelstringY-axis label
gridbooleantrueShow grid lines
legendbooleantrueShow interactive legend
tooltipbooleantrueShow hover tooltips
animatedbooleantrueAnimate entrance
stackedbooleanfalseStack series (bar/area)
horizontalbooleanfalseHorizontal bars
showPointsbooleantrueShow data points on line/area
curve'smooth' | 'linear''smooth'Line interpolation
centerValuestringDonut center value
centerLabelstringDonut center label
isLoadingbooleanfalseShow loading skeleton
colorsstring[]violet paletteCustom color palette
classNamestringAdditional CSS classes
ariaLabelstringAccessible description

ChartSeries

interface ChartSeries {
  name: string;
  data: { x: string | number; y: number }[];
  color?: string;
}

DonutSegment

interface DonutSegment {
  label: string;
  value: number;
  color?: string;
}

Accessibility

  • SVG has role="img" with aria-label
  • Hidden data table provides screen reader access to all values
  • Legend buttons are keyboard-focusable with proper ARIA labels
  • Tooltips appear on hover with series breakdown

On this page