Class Trendline

Class Trendline

Namespace: Aspose.Cells.Charts
Assembly: Aspose.Cells.dll (25.2.0)

Represents a trendline in a chart.

public class Trendline : Line

Inheritance

objectLineTrendline

Inherited Members

Line.m_lineParent, Line.CompoundType, Line.DashType, Line.CapType, Line.JoinType, Line.BeginType, Line.EndType, Line.BeginArrowLength, Line.EndArrowLength, Line.BeginArrowWidth, Line.EndArrowWidth, Line.ThemeColor, Line.Color, Line.Transparency, Line.Style, Line.Weight, Line.WeightPt, Line.WeightPx, Line.FormattingType, Line.IsAutomaticColor, Line.IsVisible, Line.IsAuto, Line.GradientFill, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
//adding a linear trendline
int index = chart.NSeries[0].TrendLines.Add(TrendlineType.Linear);
Trendline trendline = chart.NSeries[0].TrendLines[index];
//Setting the custom name of the trendline.
trendline.Name = "Linear";
//Displaying the equation on chart
trendline.DisplayEquation = true;
//Displaying the R-Squared value on chart
trendline.DisplayRSquared = true;
//Saving the Excel file
workbook.Save("book1.xls");
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
Chart.NSeries.CategoryData = "C1:C4"
'adding a linear trendline
Dim index As Int32 = chart.NSeries(0).TrendLines.Add(TrendlineType.Linear)
Dim trendline As Trendline = chart.NSeries(0).TrendLines(index)
'Setting the custom name of the trendline.
trendline.Name = "Linear"
'Displaying the equation on chart
trendline.DisplayEquation = True
'Displaying the R-Squared value on chart
trendline.DisplayRSquared = True
'Saving the Excel file
workbook.Save("book1.xls")

Properties

Backward

Returns or sets the number of periods (or units on a scatter chart) that the trendline extends backward. The number of periods must be greater than or equal to zero. If the chart type is column ,the number of periods must be between 0 and 0.5

public double Backward { get; set; }

Property Value

double

DataLabels

Represents the DataLabels object for the specified series.

public DataLabels DataLabels { get; }

Property Value

DataLabels

DisplayEquation

Represents if the equation for the trendline is displayed on the chart (in the same data label as the R-squared value). Setting this property to True automatically turns on data labels.

public bool DisplayEquation { get; set; }

Property Value

bool

DisplayRSquared

Represents if the R-squared value of the trendline is displayed on the chart (in the same data label as the equation). Setting this property to True automatically turns on data labels.

public bool DisplayRSquared { get; set; }

Property Value

bool

Forward

Returns or sets the number of periods (or units on a scatter chart) that the trendline extends forward. The number of periods must be greater than or equal to zero.

public double Forward { get; set; }

Property Value

double

Intercept

Returns or sets the point where the trendline crosses the value axis.

public double Intercept { get; set; }

Property Value

double

IsNameAuto

Returns if Microsoft Excel automatically determines the name of the trendline.

public bool IsNameAuto { get; set; }

Property Value

bool

LegendEntry

Gets the legend entry according to this trendline

public LegendEntry LegendEntry { get; }

Property Value

LegendEntry

Name

Returns the name of the trendline.

public string Name { get; set; }

Property Value

string

Order

Returns or sets the trendline order (an integer greater than 1) when the trendline type is Polynomial. The order must be between 2 and 6.

public int Order { get; set; }

Property Value

int

Period

Returns or sets the period for the moving-average trendline.

public int Period { get; set; }

Property Value

int

Remarks

This value should be between 2 and 255. And it must be less than the number of the chart points in the series

Type

Returns the trendline type.

public TrendlineType Type { get; }

Property Value

TrendlineType