MAUI | ComponentOne
Controls / FlexChart / Trend Line
In This Topic
    Trend Line
    In This Topic

    Trend line refers to a straight or a curved line that is superimposed on the chart to inform user about direction of the data or the trend, and hence helps in predicting the future values. Due to ability to depict future prices, trend lines are often used in trade analysis to understand the price movement and forecast the value of securities.

    trendline on chart

    In FlexChart, trend lines can be implemented by creating an instance of the TrendLine class. Then, you can set other relevant properties and add it to the Series collection. FlexChart supports regression as well as non-regression trend lines and the fit type and order of these lines can be specified using the FitType and Order property of the TrendLine class, respectively. The FitType property sets one of the following fit types for the trend lines using the FitType enumeration, in the FlexChart control:

    TrendLine.FitType Description
    Linear A linear trend line is the straight line that most closely approximates the data in the chart. The data is linear, if the data pattern resembles a line.
    Equation - Y(x) = C0 + C1*x
    Polynom Polynomial trend lines are curved lines that are used with fluctuating data. They are useful for analyzing gains or losses over a large data set. When using a polynomial trend line, it is important to also set the Order of the line, which can be determined by the number of fluctuations in the data.
    Equation -Y(x) = C0 + C1*x + C2*x2 + : +Cn-1*xn-1
    Logarithmic Logarithmic trend line 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 trend line can use negative and/or positive values.
    Equation - Y(x) = C0 * ln(C1*x)
    Power Power trend line is a curved line that is best used with data sets that compare measurements that increase at a specific rate — for example, the acceleration of a race car at one-second intervals. You cannot create a power trend line if your data contains zero or negative values.
    Equation - Y(x) = C0 * pow(x, C1)
    Exponent Exponential trend line is a curved line that is most useful when data values rise or fall at increasingly higher rates. You cannot create an exponential trend line if your data contains zero or negative values.
    Equation - Y(x) = C0 * exp( C1*x)
    Fourier

    Fourier trend line identifies patterns or cycles in a series data set. It removes the effects of trends or other complicating factors from the data set, thereby providing a good estimate of the direction that the data under analysis will take in the future.

    Equation - Y(x) = C0 + C1 * cos(x) + C2 * sin(x) + C3 * cos(2*x) + C4 * sin(2*x) +...
    MinX The minimum X-value on the chart.
    MinY The minimum Y-value on the chart.
    MaxX The maximum X-value on the chart.
    MaxY The maximum Y-value on the chart.
    AverageX The average X-value on the chart.
    AverageY The average Y-value on the chart.

    The following code showcases trendlines used in charts.

    XAML
    Copy Code
    <c1:FlexChart x:Name="flexChart" ChartType="Scatter" LegendPosition="Bottom"
              ItemsSource="{Binding Data}" BindingX="X" Binding="Y">
        <c1:Series SeriesName="Raw Data" />
        <c1:TrendLine x:Name="trendLine" SeriesName="Trend Line" FitType="Linear" Order="2" />
    </c1:FlexChart>
    

    Following code demonstrates the data used in the above chart.

    C#
    Copy Code
    List<Point> _data;
    Random rnd = new();
    public List<Point> Data
    {
        get
        {
            if (_data == null)
            {
                _data = new List<Point>();
                for (var i = 1; i <= 8; i++)
                    _data.Add(new Point(i, rnd.Next(100)));
            }
    
            return _data;
        }
    }