Trendlines in Stock Chart Control

26 Oct 20225 minutes to read

Trendlines are used to show the direction and speed of price.

Stock Chart supports 6 types of trendlines namely Linear,Exponential,Logarithmic,Polynomial,Power,Moving Average. By using trendline dropdown button you can add or remove the required trendline type.

Linear

A linear trendline is a best fit straight line that is used with simpler data sets.To render a linear trendline, use trendline type as Linear.

Exponential

An exponential trendline is a curved line that is most useful when data values rise or fall at increasingly higher rates. You cannot create an exponential trendline, if your data contains zero or negative values.

To render a exponential trendline, use trendline type as Exponential.

Logarithmic

A logarithmic trendline is a best-fit curved line that is most useful when the rate of change in the data increases or decreases quickly and then levels out. A logarithmic trendline can use negative and/or positive values.

To render a logarithmic trendline, use trendline type as Logarithmic.

Polynomial

A polynomial trendline is a curved line that is used when data fluctuates.

To render a polynomial trendline, use trendline type as Polynomial. polynomialOrder used to define the polynomial value.

Power

A power trendline is a curved line that is best used with data sets that compare measurements that increase at a specific rate.

To render a power trendline, use trendline type as Power.

Moving Average

A moving average trendline smoothen out fluctuations in data to show a pattern or trend more clearly.

To render a moving average trendline, use trendline type as MovingAverage.

period property defines the period to find the moving average.

<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price" seriesType="@(new List<Object>() { })" exportType="@(new List<Object>() { })" indicatorType="@(new List<Object>() { })">
                <e-stockchart-series-collection>
                    <e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
                </e-stockchart-series-collection>
            </ejs-stockchart>

    <script src="~/scripts/chart/financial-data.js"></script>
    <script>
        var data = chartData;
            function stockload(args) {
                args.stockChart.series[0].dataSource = data;
                args.stockChart.series[0].trendlines= [{ type: 'MovingAverage', enableTooltip: false }]

            }
    </script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
    public partial class StockChartController : Controller
    {
        public IActionResult Default()
        {
            return View();
        }
    }
}

Customization of Trendline

The fill and width properties are used to customize the appearance of the trendline.

<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price" seriesType="@(new List<Object>() { })" exportType="@(new List<Object>() { })" indicatorType="@(new List<Object>() { })">
                <e-stockchart-series-collection>
                    <e-stockchart-series type='Candle' xName="x">
                        <e-stockseries-stockcharttrendlines>
                            <e-trendline type="MovingAverage" enableTooltip="false" fill="red" width="2"></e-trendline>
                        </e-stockseries-stockcharttrendlines>
                    </e-stockchart-series>
                </e-stockchart-series-collection>
            </ejs-stockchart>

    <script src="~/financial-data.js"></script>
    
    <script>
        var data = chartData;
            function stockload(args) {
                args.stockChart.series[0].dataSource = data;
            }
    </script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
    public partial class StockChartController : Controller
    {
        public IActionResult Default()
        {
            return View();
        }
    }
}