Search results

Trendlines

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

Trendlines can be generated for Cartesian type series (Line, Column, Scatter, Area, Candle, Hilo etc.) except bar type series. You can add more than one trendline to a series.

Chart supports 6 types of trendlines.

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.

razor
linear.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

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.

razor
exponential.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
            series.Trendlines(ViewBag.trendLines)
            .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
            .XName("x").YName("y")
            .Marker(ViewBag.marker)
            .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add();
             }).PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
             .MajorGridLines(ViewBag.majorGridLines))
             .PrimaryYAxis(py => py.Title("Rupees against Dollars")
             .Interval(10)
             .MajorTickLines(ViewBag.majorTickLines)
             .LineStyle(ViewBag.lineStyle))
             .ChartArea(area => area.Border(ViewBag.ChartBorder))
             .Title("Historical Indian Rupee Rate (INR USD)")
             .LegendSettings(lg => lg.Visible(false))
             .Tooltip(tt => tt.Enable(true)).Render()
}
 <script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

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.

razor
logarithmic.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

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.

razor
polynomial.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

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.

razor
power.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Scatter)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("powerData")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            List<powerData> chartData = new List<powerData>
            {
                    new powerData { x= 1, y= 10 },
                    new powerData { x= 2, y= 50 },
                    new powerData { x= 3, y= 80 },
                    new powerData { x= 4, y= 110 },
                    new powerData { x= 5, y= 180 },
                    new powerData { x= 6, y= 220 },
                    new powerData { x= 7, y= 300 },
                    new powerData { x= 8, y= 370 },
                    new powerData { x= 9, y= 490 },
                    new powerData { x= 10, y= 500 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class powerData
        {
            public double x;
            public double y;
        }

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.

razor
movingaverage.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Scatter)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("powerData")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

Customization of Trendlines

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

razor
custom-trendline.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Scatter)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("powerData")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

Forecasting

Trendlines forecasting is the prediction of future/past situations.

Forecasting can be classified into two types as follows

Forward Forecasting Backward Forecasting

Forward Forecasting

The value set for forwardForecast is used to determine the distance moving towards the future trend.

razor
forward-forecast.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }

Backward Forecasting

The value set for the backwardForecast is used to determine the past trends.

razor
backward-forecast.cs
@using Syncfusion.EJ2;
@section ControlsSection{   
             @Html.EJS().Chart("container").Series(series =>
             {
                 series.Trendlines(ViewBag.trendLines)
                 .Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
                 .XName("x").YName("y")
                 .Marker(ViewBag.marker)
                .DataSource("series1")
                .Name("Rupees")
                .Width(2).Add(); })
                .PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
                .MajorGridLines(ViewBag.majorGridLines))
                .PrimaryYAxis(py => py.Title("Rupees against Dollars")
                .Interval(10)
                .MajorTickLines(ViewBag.majorTickLines)
                .LineStyle(ViewBag.lineStyle))
                .ChartArea(area => area.Border(ViewBag.ChartBorder))
                .Title("Historical Indian Rupee Rate (INR USD)")
                .LegendSettings(lg => lg.Visible(false))
                .Tooltip(tt => tt.Enable(true)).Render()
}
<script type="text/javascript">
        var series1 = [];
        var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
            13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
            41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
        var point1;
        var i;
        var j = 0;
        for (i = 1973; i <= 2013; i++) {
            point1 = { x: i, y: yValue[j] };
            series1.push(point1);
            j++;
        }
        var powerData = [
            { x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
            { x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
        ];
    </script>
public IActionResult Index()
        {
            return View();
        }