Table of Contents

Interface IChartTrendLine

Namespace
Spire.Xls.Core
Assembly
Spire.XLS.dll

Represents ChartTrendLine interface.

public interface IChartTrendLine

Properties

Backward

Represents number of periods that the trendline extends backward. The following code illustrates how to set backward forecast value for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ScatterMarkers);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Set X axis minimum and maximum values
chart.PrimaryCategoryAxis.MinValue = -2;
chart.PrimaryCategoryAxis.MaxValue = 2;

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set backward forecast value
trendline.Backward = 3;

//Save to file
workbook.SaveToFile("Chart.xlsx");
double Backward { get; set; }

Property Value

double

Border

Represents border object. Read only. The following code illustrates how to access and format the IChartBorder for IChartTrendLine:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
IChart chart = worksheet.Charts.Add();

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;

//Add trendline
IChartTrendLine trendline = trendLines.Add();

//Set trendline broder properties
trendline.Border.Color = Color.Red;

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartBorder Border { get; }

Property Value

IChartBorder

Chart3DOptions

Gets the IThreeDFormat object. Read-only.[Deprecated]

IFormat3D Chart3DOptions { get; }

Property Value

IFormat3D

DataLabel

Returns data label. Read only. The following code illustrates how to enable and set IChartTextArea text for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Enable trendline data label by DisplayRSquared
trendline.DisplayRSquared = true;

//Set data label text
trendline.DataLabel.Text = "y=10*x";

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartDataLabels DataLabel { get; }

Property Value

IChartDataLabels

DisplayEquation

True if the equation for the trendline is displayed on the chart. The following code illustrates how to display equation for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set equation in trendline
trendline.DisplayEquation = true;

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool DisplayEquation { get; set; }

Property Value

bool

DisplayRSquared

True if the R-squared value of the trendline is displayed on the chart. The following code illustrates how to display RSquared for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set RSquared value for trendline
trendline.DisplayRSquared = true;

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool DisplayRSquared { get; set; }

Property Value

bool

Formula

Return trendline formula. Read only.

string Formula { get; }

Property Value

string

Forward

Represents number of periods that the trendline extends forward. The following code illustrates how to set Forward forecast value for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ScatterMarkers);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Set X axis minimum and maximum values
chart.PrimaryCategoryAxis.MinValue = -2;
chart.PrimaryCategoryAxis.MaxValue = 2;

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set backward forecast value
trendline.Forward = 3;

//Save to file
workbook.SaveToFile("Chart.xlsx");
double Forward { get; set; }

Property Value

double

Intercept

Represents point where the trendline crosses the value axis. The following code illustrates how to set intercept value for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ScatterMarkers);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set intercept value
trendline.Intercept = 10;

//Save to file
workbook.SaveToFile("Chart.xlsx");
double Intercept { get; set; }

Property Value

double

InterceptIsAuto

True if the point where the trendline crosses the value axis is automatically determined by the regression. The following code illustrates how to check whether the IChartTrendLine object intercept value is automatic or not:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ScatterMarkers);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set intercept value
trendline.Intercept = 10;

//Check trendline intercept is automatic
Console.WriteLine("Is Trendline Intercept value is automatic:" + trendline.InterceptIsAuto.ToString());

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool InterceptIsAuto { get; }

Property Value

bool

Name

Represents trendline name. The following code illustrates how to access name from IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add(TrendLineType.Logarithmic);

//Get trendline Name
Console.WriteLine(trendline.Name);

//Save to file
workbook.SaveToFile("Chart.xlsx");
string Name { get; set; }

Property Value

string

NameIsAuto

Indicates if name is default. The following code illustrates how to check whether the IChartTrendLine object name is default or not:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add(TrendLineType.Logarithmic);

//Set trendline name
trendline.Name = "Trendline 1";

//Check trendline name is automatic
Console.WriteLine(trendline.NameIsAuto);

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool NameIsAuto { get; set; }

Property Value

bool

Order

Represents for Moving Averange and Polynomial trend line type order value. The following code illustrates how to set order value for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set trendline type
trendline.Type = TrendLineType.Polynomial;

//Set trendline order
trendline.Order = 6;

//Save to file
workbook.SaveToFile("Chart.xlsx");
int Order { get; set; }

Property Value

int

Shadow

Gets the shadow.Read-only. The following code illustrates how to access and format the IShadow for IChartTrendLine:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart
Chart chart = worksheet.Charts.Add(ExcelChartType.ScatterMarkers);

//Add serie and set serie Y and X Values
IChartSerie serie = chart.Series.Add();
serie.Values = worksheet.Range["A2:C2"];
serie.CategoryLabels = worksheet.Range["A1:C1"];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set trendline shadow color
trendline.Shadow.Color = Color.Red;

//Set trendline shadow outer presets
trendline.Shadow.ShadowOuterType = XLSXChartShadowOuterType.OffsetDiagonalTopRight;

//Save to file
workbook.SaveToFile("Chart.xlsx");
IShadow Shadow { get; }

Property Value

IShadow

Type

Represents trend line type. The following code illustrates how to set TrendLineType for IChartTrendLine object:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create chart and Get chart serie
Chart chart = worksheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = worksheet.Range["A1:C3"];
IChartSerie serie = chart.Series[0];

//Get chart trendlines collection and Add trendline
IChartTrendLines trendLines = serie.TrendLines;
IChartTrendLine trendline = trendLines.Add();

//Set trendline type
trendline.Type = TrendLineType.Polynomial;

//Save to file
workbook.SaveToFile("Chart.xlsx");
TrendLineType Type { get; set; }

Property Value

TrendLineType

Methods

ClearFormats()

Clears current trend line.

void ClearFormats()