Skip to content

Getting Started with Charts

The @ripl/charts package provides pre-built, interactive chart components on top of the Ripl core rendering engine. Every chart inherits animated transitions, pointer events, responsive sizing, and context-agnostic rendering (Canvas or SVG) out of the box.

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' },
    ],
});

This creates a fully interactive bar chart with animated entry, tooltips on hover, and axis labels — all with zero additional configuration.

Updating Data

Call chart.update() with partial options to reactively update the chart. Changes animate smoothly — 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 },
    ],
});

You can update any option — not just data:

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

Common Options

All charts extend BaseChartOptions and share these core options:

OptionTypeDefaultDescription
paddingPartial<ChartPadding>{ top: 10, right: 10, bottom: 10, left: 10 }Inner padding around the chart area
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

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 | ChartLegendOptionsfalseShow/configure series legend
crosshairboolean | ChartCrosshairOptionsvariesShow/configure crosshair tracking

See Shared Options for a complete reference on each of these.

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

ChartFactoryKey Features
BarcreateBarChartGrouped, stacked, horizontal
LinecreateLineChart13 interpolation modes, markers
AreacreateAreaChartStacked, gradient fills
PiecreatePieChartDonut mode, slice animations
ScattercreateScatterChartBubble sizing, multi-series
RadarcreateRadarChartMulti-series overlay
HeatmapcreateHeatmapChartColor-encoded matrix
TreemapcreateTreemapChartHierarchical proportions
FunnelcreateFunnelChartConversion funnels
GaugecreateGaugeChartRadial progress, tick marks
Polar AreacreatePolarAreaChartRadial bar segments
SankeycreateSankeyChartFlow diagrams
ChordcreateChordChartRelationship matrices
SunburstcreateSunburstChartHierarchical rings
TrendcreateTrendChartSparkline-style

Next Steps