Trend lines in JavaScript Chart control

18 Nov 20181 minute to read

Trendlines help identify patterns, direction, and overall trends in numerical data. They project the general movement of data values and are widely used in analytics, forecasting, and financial charts. Trendlines can be added to Cartesian series types such as Line, Column, Scatter, Area, Candle, and Hilo (excluding bar series). Multiple trendlines can be added to a single series based on the analysis needs.

Charts support six types of trendlines: Linear, Exponential, Logarithmic, Polynomial, Power, and Moving Average.

Linear

A linear trendline is a straight, best‑fit line used to describe data with a constant rate of increase or decrease. Set the trendline type to Linear and inject the Trendlines module using Chart.Inject(Trendlines) method.

Exponential

An exponential trendline displays a curved pattern useful when data rises or falls at increasing rates. Exponential trendlines cannot be generated if the dataset includes zero or negative values.

Set the trendline type to Exponential and inject the Trendlines module using Chart.Inject(Trendlines) method.

Logarithmic

A logarithmic trendline is a best‑fit curved line suitable when the data increases or decreases quickly and then stabilizes. It supports both positive and negative values.

Set type to Logarithmic and inject the Trendlines module using Chart.Inject(Trendlines) method.

Polynomial

A polynomial trendline is useful when data fluctuates. It uses a curved line that can model more complex datasets.

Set type to Polynomial and inject the Trendlines module using Chart.Inject(Trendlines) method. Use polynomialOrder to define the degree of the polynomial.

Power

A power trendline is ideal for datasets where measurements increase at a constant rate. It displays a curved line that best fits exponential growth or decay patterns.

Set type to Power and inject the Trendlines module using Chart.Inject(Trendlines) method.

Moving average

A moving average trendline smooths fluctuations to reveal overall trends more clearly. The period property specifies the number of data points used to calculate each average.

Set type to MovingAverage and inject the Trendlines module using Chart.Inject(Trendlines) method.

Customization of trendline

Customize trendline appearance using the fill property for color and the width property for line thickness.

Forecasting

Trendline forecasting extends the existing trendline to estimate future and past values.

Forward forecasting

Use the forwardForecast property to extend the trendline into the future.

Backward forecasting

Use the backwardForecast property to extend the trendline into past data points.

Show or hide a trendline

Control visibility using the visible property of the trendline.