Compat
# fillPlaceholders function
packages/highcharts/src/compat.ts:128fillPlaceholders(template: string, stats: RegressionSuccess | SmoothSuccess, decimalPlaces: number): stringSubstitutes
%eq, %r2, %r and %se, globally rather than once each.Parameters
| Name | Type | Description |
|---|---|---|
| template | string | — |
| stats | RegressionSuccess | SmoothSuccess | — |
| decimalPlaces | number | — |
Returns
string
# withRegression function
packages/highcharts/src/compat.ts:252withRegression<T extends RegressionChartOptions>(chartOptions: T): AnalyseResult<T>Drop-in replacement for
highcharts-regression.Reads regression: true and regressionSettings off each series exactly as
the incumbent does, so an existing chart config needs no edits. Internally it
translates to the native fit API and calls {@link analyse}, so the facts and
accessible descriptions come along for free.
Deliberate behaviour differences, each of which fixes a defect:
%rcarries its sign. The incumbent computesMath.sqrt(rSquared), so a perfectly inverse relationship reportsr = 1. Charts with a negative correlation will show a different number after migrating.- Input options and series data are never mutated. The incumbent writes array indices onto live point objects and sorts the caller’s array in place; a chart relying on that side effect will need its own sort.
- Degenerate data draws no line. The incumbent returns a flat line through the
mean with
r² = 0and no error signal; here the series is omitted and the reason appears on the outcome. useAllSeriesworks. In the incumbent it raises aReferenceError.- No plot-line markers are added, so nothing new appears on a migrated chart.
loess caveats: a smoother fits no global model, so %eq renders as
“LOESS smoothing” and %r as “n/a” — there is no equation, and no slope to
take a sign from. extrapolate is also inert, since a LOESS value at an
unobserved x would need the whole dataset refitted.
Parameters
| Name | Type | Description |
|---|---|---|
| chartOptions | T | Options in the incumbent’s shape. |
Returns
AnalyseResult<T>Rewritten options plus one {@link FitOutcome} per fitted series.
Example
const { options } = withRegression({
series: [{
name: "Sales",
data: [[1, 2], [2, 4]],
regression: true,
regressionSettings: { type: "polynomial", order: 3, name: "Fit: %eq (R²=%r2)" },
}],
});
Highcharts.chart("container", options);# RegressionChartOptions interface
packages/highcharts/src/compat.ts:63interface RegressionChartOptions extends ChartOptions {
series?: RegressionSeries[];
}# RegressionSeries interface
packages/highcharts/src/compat.ts:58interface RegressionSeries extends FittableSeries {
regression?: boolean;
regressionSettings?: RegressionSettings;
}A series in the incumbent’s shape.
# RegressionSettings interface
packages/highcharts/src/compat.ts:19interface RegressionSettings {
/** @default "linear" */
type?: "linear" | "exponential" | "polynomial" | "power" | "logarithmic" | "loess";
/** Polynomial degree. @default 2 */
order?: number;
/**
* Legend and tooltip name. Supports `%eq`, `%r`, `%r2` and `%se`.
* @default "Equation: %eq"
*/
name?: string;
/** Decimal places for the fitted values. @default 2 */
decimalPlaces?: number;
/** Highcharts series type for the drawn line. @default "spline" */
lineType?: string;
/** @default 2 */
lineWidth?: number;
/** @default "solid" */
dashStyle?: string;
color?: string;
/** Fit across every series on the chart rather than just this one. @default false */
useAllSeries?: boolean;
/** Steps projected past the last observation. @default 0 */
extrapolate?: number;
/** LOESS neighbourhood size, as a percentage of the sample. @default 25 */
loessSmooth?: number;
/** Draw the line itself. @default true */
visible?: boolean;
/** Show the line but not its legend entry. @default false */
hideInLegend?: boolean;
index?: number;
legendIndex?: number;
tooltip?: Record<string, unknown>;
/** Label specific points of the fitted line. Supports the same placeholders as `name`. */
dataLabels?: { pointIndex: number; format: string }[];
/** Merged into the generated series, last. */
regressionSeriesOptions?: Record<string, unknown>
// …truncated
Type shortened for readability — see the source for the full definition.
The
regressionSettings object accepted by highcharts-regression v2.2.0,
reproduced so an existing chart config can be moved across unchanged.
See also
- {@link withRegression} for the behaviour differences.