Skip to content

Forecast API

A plugin that turns any time chart into a forecast, projecting future steps with a confidence band; for the full story see the Insights guide.

Try it - toggle the forecast, its band, and narration:

forecast · line

Import

ts
import { forecast } from "@michi-vz/insights/forecast";

forecast(options?) returns a plugin you pass in the chart's mount options. It works on Line, Fan, Range, Area, Vertical-Stack-Bar, Ribbon, and Bar-Bell charts.

ts
mountLineChart(el, props, { plugins: [forecast({ horizon: 4 })] });

Signature & options

NameTypeDefaultWhat it does
method"holt-winters" or "linear" (lazy "arima")"holt-winters"Forecasting model used to project future steps.
horizonnumber4Number of future steps to forecast.
levelnumber0.95Confidence level for the prediction band.
levelsnumber[]optionalExtra nested band levels for a fan chart.
targetstring or string[]allRestrict the forecast to these series labels.
scenariosArray<{ name: string; growth: number }>optionalWhat-if lines drawn from custom growth rates.
trendlinebooleanfalseOverlay a regression line.
threshold{ value: number; label?: string }optionalReference line plus a projected "fall point".
onThresholdBreach(b) => voidoptionalFires when the forecast is projected to cross the threshold.
zonebooleantrueShade the forecast region to highlight prediction versus actual.

Also exported from this subpath: forecastFan(history, options?, label?), computeForecast, decompose, detectPeriod, detectChangepoints, monteCarloForecast, requiredGrowth, requiredRunRate, pacingToGoal, and FORECASTABLE_CHARTS.

Example

ts
import { mountLineChart } from "@michi-vz/core";
import { forecast } from "@michi-vz/insights/forecast";

mountLineChart(el, props, {
  plugins: [
    forecast({
      method: "holt-winters",
      horizon: 4,
      threshold: { value: 200, label: "Target" },
      zone: true,
    }),
  ],
});

Insights guide

Free and open source. MIT licensed.