# How to add a trendline in a chart

A trendline is used to show the trend of data series and predict future tendency. Totally, there are six different types: linear trendline, logarithmic trendline, polynomial trendline, power trendline, exponential trendline, and moving average trendline. We may choose different trendline based on the data type we have for different trendline has different advantages to show trend.

For example, a linear trendline works well to show the increase or decrease of data at a steady rate while a logarithmic trendline is often used to show the rate of change in the data increases or decreases quickly and then levels out.  Step 1: Load the workbook and create a sheet

```Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;
```

Step 2: Select targeted chart, add trendline and set its type

```//select chart and set logarithmic trendline
Chart chart = sheet.Charts;
//select chart and set moving_average trendline
Chart chart1 = sheet.Charts;
//select chart and set linear trendline
Chart chart2 = sheet.Charts;
//select chart and set exponential trendline
Chart chart3 = sheet.Charts;
```

Step 3: Save and launch the document

```workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("S3.xlsx");
```

Full code:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;

Chart chart = sheet.Charts;

Chart chart1 = sheet.Charts;

Chart chart2 = sheet.Charts;

Chart chart3 = sheet.Charts; 