Trendline Class

Represents a trendline in a chart.
Inheritance Hierarchy

Namespace:  Aspose.Cells.Charts
Assembly:  Aspose.Cells (in Aspose.Cells.dll) Version: 21.7.0.0 (21.7)
Syntax
public class Trendline : Line

The Trendline type exposes the following members.

Properties
  NameDescription
Public propertyBackward
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 and equal to zero. If the chart type is column ,the number of periods must be between 0 and 0.5
Public propertyBeginArrowLength
Specifies the length of the arrowhead for the begin of a line.
(Inherited from Line.)
Public propertyBeginArrowWidth
Specifies the width of the arrowhead for the begin of a line.
(Inherited from Line.)
Public propertyBeginType
Specifies an arrowhead for the begin of a line.
(Inherited from Line.)
Public propertyCapType
Specifies the ending caps.
(Inherited from Line.)
Public propertyColor
Represents the Color of the line.
(Inherited from Line.)
Public propertyCompoundType
Specifies the compound line type
(Inherited from Line.)
Public propertyDashType
Specifies the dash line type
(Inherited from Line.)
Public propertyDataLabels
Represents the DataLabels object for the specified ASeries.
Public propertyDisplayEquation
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 propertyDisplayRSquared
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 propertyEndArrowLength
Specifies the length of the arrowhead for the end of a line.
(Inherited from Line.)
Public propertyEndArrowWidth
Specifies the width of the arrowhead for the end of a line.
(Inherited from Line.)
Public propertyEndType
Specifies an arrowhead for the end of a line.
(Inherited from Line.)
Public propertyFormattingType
Gets or sets format type.
(Inherited from Line.)
Public propertyForward
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 and equal to zero.
Public propertyGradientFill
Represents gradient fill.
(Inherited from Line.)
Public propertyIntercept
Returns or sets the point where the trendline crosses the value axis.
Public propertyIsAuto
Indicates whether this line style is auto assigned.
(Inherited from Line.)
Public propertyIsAutomaticColor
Indicates whether the color of line is auotmatic assigned.
(Inherited from Line.)
Public propertyIsNameAuto
Returns if Microsoft Excel automatically determines the name of the trendline.
Public propertyIsVisible
Represents whether the line is visible.
(Inherited from Line.)
Public propertyJoinType
Specifies the joining caps.
(Inherited from Line.)
Public propertyLegendEntry
Gets the legend entry according to this trendline
Public propertyName
Returns the name of the trendline.
Public propertyOrder
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 propertyPeriod
Returns or sets the period for the moving-average trendline.
Public propertyStyle
Represents the style of the line.
(Inherited from Line.)
Public propertyThemeColor
Gets and sets the theme color.
(Inherited from Line.)
Public propertyTransparency
Returns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).
(Inherited from Line.)
Public propertyType
Returns the trendline type.
Public propertyWeight
Gets or sets the WeightType of the line.
(Inherited from Line.)
Public propertyWeightPt
Gets or sets the weight of the line in unit of points.
(Inherited from Line.)
Public propertyWeightPx
Gets or sets the weight of the line in unit of pixels.
(Inherited from Line.)
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Fields
  NameDescription
Protected fieldm_lineParent (Inherited from Line.)
Examples
[C#]

//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("C:\\book1.xls");

[Visual Basic]

'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("C:\\book1.xls")
See Also