# Creating TrendLines

## Content



### Creating TrendLines at Design Time

TrendLines can be created at design time using the **TrendLine Collection Editor**. Using the collection editor, you may add, modify and remove trend lines. For more information on the **TrendLine Collection Editor**, see [TrendLine Collection Editor](/componentone/docs/win/online-chart2d/designtimesupport/c1chartcollectionedi/trendlinecollectione).

### Creating TrendLines Programmatically

To create a TrendLine programmatically, create instance of TrendLine object and set its properties. The TrendLine can be created using its constructor or AddNewTrendLine.TrendLinesCollection() method of TrendLinesCollection.

The following code adds a red TrendLine to ChartGroup(0) of the Chart:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
' create trend line        
Dim tl As C1.Win.C1Chart.TrendLine = New C1.Win.C1Chart.TrendLine()
' first data series       
tl.SeriesIndex = 0       
' set line color and thickness      
tl.LineStyle.Color = Color.Red      
tl.LineStyle.Thickness = 2
' show formula in legend    
tl.Text = "{#FORMULA}"       
' add trend to the chart        
c1Chart1.ChartGroups(0).ChartData.TrendsList.Add(tl)
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
// create trend line       
C1.Win.C1Chart.TrendLine tl = new C1.Win.C1Chart.TrendLine();        
// first data series       
tl.SeriesIndex = 0;        
// set line color and thickness       
tl.LineStyle.Color = Color.Red;  
tl.LineStyle.Thickness = 2;     
// show formula in legend    
tl.Text = "{#FORMULA}";     
// add trend to the chart    
c1Chart1.ChartGroups[0].ChartData.TrendsList.Add( tl);
```

DOC-DETAILS-TAG-CLOSE

This topic illustrates the following:

![](https://cdn.mescius.io/document-site-files/images/70bd33a2-280e-4cc3-a1c0-7b827eceb8aa/imagesext/image9_153.png)

The red trend line connects the first and last data points.

## See Also

[Regression TrendLines](/componentone/docs/win/online-chart2d/chartingdata/workingwithtrendline/regressiontrendlines)