Skip to content

Getting Started with Charts

@ripl/charts is a set of interactive chart types built on the Ripl core rendering engine. Every chart animates its data transitions, emits pointer events, resizes with its container, and draws through the same Context, so one chart definition renders to Canvas or SVG.

NOTE

For the full API, see the Charts API Reference.

Installation

bash
npm install @ripl/charts

TIP

@ripl/charts depends on @ripl/core, which is installed automatically. You don't need to install it separately.

Your First Chart

Every chart follows the same pattern:

  1. Import the factory function for the chart type
  2. Call it with a target (CSS selector, HTMLElement, or Context) and an options object
  3. Update the chart reactively via chart.update(options)
ts
import {
    createBarChart,
} from '@ripl/charts';

const chart = createBarChart('#chart-container', {
    data: [
        {
            month: 'Jan',
            sales: 120,
            costs: 80,
        },
        {
            month: 'Feb',
            sales: 200,
            costs: 110,
        },
        {
            month: 'Mar',
            sales: 150,
            costs: 90,
        },
    ],
    key: 'month',
    series: [
        {
            id: 'sales',
            value: 'sales',
            label: 'Sales',
        },
        {
            id: 'costs',
            value: 'costs',
            label: 'Costs',
        },
    ],
});

That's all it takes to get a fully interactive bar chart, complete with animated entry, hover tooltips, and axis labels.

Updating Data

Call chart.update() with partial options to update the chart in place. Changes animate: new data points enter, removed points exit, and existing points transition to their new positions.

ts
chart.update({
    data: [
        {
            month: 'Jan',
            sales: 180,
            costs: 100,
        },
        {
            month: 'Feb',
            sales: 220,
            costs: 130,
        },
        {
            month: 'Mar',
            sales: 170,
            costs: 95,
        },
        {
            month: 'Apr',
            sales: 300,
            costs: 150,
        },
    ],
});

Any option can be updated this way, not only the data:

ts
chart.update({ stacked: true });
chart.update({ orientation: 'horizontal' });
chart.update({ legend: true });

Common Options

All charts extend BaseChartOptions and share these core options:

OptionTypeDefaultDescription
paddingPaddingInput16Space reserved around the chart area: a number for every edge, a [top, right, bottom, left] tuple, or a partial per-edge object
animationboolean | Partial<ChartAnimationOptions>{ enabled: true, duration: 1000, ease: 'easeOutCubic' }Animation toggle or configuration
titlestring | Partial<ChartTitleOptions>Chart title text or configuration
autoRenderbooleantrueAutomatically render on creation and update
themestring | Thememodule defaultA registered theme name ('light'/'dark'/'auto') or a Theme object
descriptionstringtitle textAccessible description announced by screen readers

Most chart types also support these feature options:

OptionTypeDefaultDescription
axisboolean | ChartAxisOptionstrueShow/configure x and y axes
gridboolean | ChartGridOptionstrueShow/configure background grid lines
tooltipboolean | ChartTooltipOptionstrueShow/configure hover tooltips
legendboolean | ChartLegendOptionsautoShow/configure series legend (shown by default for charts with more than one series/segment, at the bottom)
crosshairboolean | ChartCrosshairOptionsvariesShow/configure crosshair tracking

See Shared Options for a complete reference on each of these, and each chart's own page for the full, generated list of every option it accepts.

SVG Rendering

Charts render to Canvas by default. To use SVG, pass an SVG context as the target:

ts
import {
    createBarChart,
} from '@ripl/charts';

import {
    createContext,
} from '@ripl/svg';

const svgContext = createContext('#chart-container');

const chart = createBarChart(svgContext, {
    data: [/* ... */],
    key: 'month',
    series: [/* ... */],
});

Destroying a Chart

Call destroy() to clean up the chart, its scene, renderer, and all event subscriptions:

ts
chart.destroy();

Available Charts

Cartesian

ChartFactoryDescription
LinecreateLineChartOne or more series as lines, with 13 interpolation modes per series, optional markers, dual y-axes, crosshair, grid and legend.
BarcreateBarChartGrouped, stacked or 100% stacked bars, vertical or horizontal, with rounded corners, value labels, tooltips and a legend.
AreacreateAreaChartFilled bands beneath line series, stacked or overlaid, with per-series fill opacity, crosshair, grid and tooltips.
TrendcreateTrendChartLine, bar and area series mixed on shared axes, with per-type stacking and an overview strip for windowing the x-range.
ScattercreateScatterChartPoints across x and y for two continuous measures, with optional size-encoded bubbles, dual-axis crosshair and pan-zoom.
StockcreateStockChartOHLC candlesticks with a labeled volume sub-chart, separate up and down colors, crosshair, annotations and pan-zoom.
HistogramcreateHistogramChartThe distribution of a numeric field, binned into bars over a continuous value axis with nice bins or explicit thresholds.
Box PlotcreateBoxPlotChartAn interquartile box, median, 1.5x IQR whiskers and outliers per category, from the shared boxplotStats transform.

Radial & Polar

ChartFactoryDescription
Pie/DonutcreatePieChartProportions as angular slices, with an inner radius for a donut, constant-width slice gaps, labels and hover dimming.
Polar AreacreatePolarAreaChartEqual-angle segments whose radius encodes value, over configurable value rings, with labels and a legend.
Polar ScattercreatePolarScatterChartPoints on a circular grid where angle and radius each encode a variable, and a third can drive marker size.
Radial BarcreateRadialBarChartConcentric rings whose arcs sweep to each value, with a faint track behind, configurable angular range and rounded caps.
RadarcreateRadarChartOne polygon per series across shared category spokes, with configurable grid rings, markers, labels and a legend.
GaugecreateGaugeChartA single value on a semi-circular arc between a min and max, with tick marks, tick labels and a custom value formatter.

Hierarchical

ChartFactoryDescription
TreemapcreateTreemapChartA total tiled into nested rectangles whose areas encode value, with configurable gaps, corner radius and automatic labels.
Packed CirclecreatePackedCircleChartCircles whose areas encode value, packed tightly without overlap inside one containing circle, with labels on the larger ones.
SunburstcreateSunburstChartA tree as concentric rings, one ring per depth level, where each arc's width is its share of its parent.

Network & Flow

ChartFactoryDescription
FunnelcreateFunnelChartOrdered stages as progressively narrowing bars, so each step's drop-off is the width it loses. Gaps and corners are configurable.
SankeycreateSankeyChartWeighted flows between nodes as proportional links, laid out automatically. For energy flows, budgets and user journeys.
Force-DirectedcreateForceDirectedChartA node-link graph laid out by a deterministic physics simulation, with tunable charge, link distance and centering.
Arc DiagramcreateArcDiagramChartNodes along one axis joined by arcs whose thickness encodes link weight, horizontally or vertically, sized by degree.
ChordcreateChordChartGroup-to-group flows from a square matrix as ribbons inside a ring of arcs, with hover dimming and configurable gaps.

Specialized

ChartFactoryDescription
HeatmapcreateHeatmapChartOne value across two categorical axes as colored cells, with a configurable gradient and a continuous color legend.
GanttcreateGanttChartTasks as bars on a time axis, with progress overlays, finish-to-start dependency connectors, a today marker and tooltips.
RealtimecreateRealtimeChartA sliding window of streaming values that scrolls as you push new ones, with a fixed window size and optional area fills.

Next Steps

  • Shared Options: the full reference for axis, legend, tooltip, grid, and crosshair configuration
  • Bar Chart: grouped, stacked and horizontal bars, with every shared option in play
  • Theming: light/dark/colorblind themes and custom palettes
  • Annotations: reference lines, bands, and point markers
  • Panning & Zooming: interactive navigation and the overview strip
  • Custom Charts: build your own chart type on the Chart base class
  • Charts API Reference: full TypeScript API documentation