﻿ Trend Lines | FlexChart | ComponentOne
FlexChart | ComponentOne
FlexChart / Working with FlexChart / Trend Lines
In This Topic
Trend Lines
In This Topic

Trend lines are an important tool for analyzing data. Trend line indicates the general rate of increase or decrease of Y data over X data in a chart. A common scenario is measuring the rate change of sales price over time. FlexChart control supports trend lines through a built-in TrendLine class for ease of use during implementation. Trend lines are most commonly used in Line, Column, Bar, or Scatter charts.

FlexChart supports the following regression and non-regression trend lines.

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
Polynomial 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.

To implement trend line in FlexChart, use the TrendLine class that inherits the Series class. To begin with, create an instance of TrendLine class, and then use the TrendLine object to specify its properties. Once, the associated properties are set, add the trend line to the FlexChart using Series.Add method.

The following image shows how FlexChart appears after adding a linear trend line. Copy Code
```<c1:C1FlexChart x:Name="flexChart" Background="White" ChartType="Scatter" ItemsSource="{Binding Data}" ToolTipContent="{}{y}" Grid.Row="1">
<c1:C1FlexChart.AxisY>
<c1:Axis Min="0" Max="100" AxisLine="False" MajorGrid="True" MajorTickMarks="None" />
</c1:C1FlexChart.AxisY>
<c1:Series SeriesName="Base Data" BindingX="X" Binding="Y"/>
<c1:TrendLine SeriesName="Trend Line" x:Name="trendLine" Binding="Y" BindingX="X" Order="4"/>
</c1:C1FlexChart>
```
HTML
Copy Code
```public partial class Trendline
{
ObservableCollection<DataItem> dataList = new ObservableCollection<DataItem>();
public Form1()
{
InitializeComponent();
var rnt = new Random();
for (int i = 1; i < 30; i++)
{
dataList.Add(new DataItem() { X = i, Y = rnt.Next(100) });
}
}
public class DataItem
{
int _y;
public int X { get; set; }

public int Y
{
get { return _y; }
set
{
if (value == _y) return;
_y = value;
}
}}
}
}
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7174646,"math_prob":0.9704551,"size":3820,"snap":"2022-40-2023-06","text_gpt3_token_len":990,"char_repetition_ratio":0.13548218,"word_repetition_ratio":0.07903226,"special_character_ratio":0.2591623,"punctuation_ratio":0.10719323,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9939107,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-02T14:33:45Z\",\"WARC-Record-ID\":\"<urn:uuid:8495e1b8-4a61-479a-b8b1-04bac2ae44b7>\",\"Content-Length\":\"18745\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:23212d59-fffb-48fa-b5f1-c7ea8fdc800c>\",\"WARC-Concurrent-To\":\"<urn:uuid:591fa496-b7b5-446f-855f-2590098ad577>\",\"WARC-IP-Address\":\"20.36.236.120\",\"WARC-Target-URI\":\"https://www.grapecity.com/componentone/docs/wpf/online-flexchart/TrendLines.html\",\"WARC-Payload-Digest\":\"sha1:EDEVCPEBP2U3M7FAJTG2Q3ZXA2UMBADA\",\"WARC-Block-Digest\":\"sha1:HCZTBUYJNQDCYHMZ7LJ2TOTNRVMOLFFZ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500028.12_warc_CC-MAIN-20230202133541-20230202163541-00720.warc.gz\"}"}