Trendline

Trendline class

Represents a trendline in a chart.

class Trendline extends Line;

Example

const { Workbook, ChartType, TrendlineType, SaveFormat } = AsposeCells;

//Instantiating a Workbook object
var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "A4" cell
worksheet.cells.get("A4").putValue(200);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(60);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(32);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);
//Adding a sample value to "B4" cell
worksheet.cells.get("B4").putValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.cells.get("C1").putValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.cells.get("C2").putValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.cells.get("C3").putValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.cells.get("C4").putValue("Y2");
//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(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
var index = chart.nSeries.get(0).trendLines.add(TrendlineType.Linear);
var trendline = chart.nSeries.get(0).trendLines.get(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
var uint8Array = workbook.save(SaveFormat.Xlsx);

Constructors

NameDescription
constructor(Line)Constructs from a parent object convertible to this.

Properties

PropertyTypeDescription
isNameAutobooleanReturns if Microsoft Excel automatically determines the name of the trendline.
typeTrendlineTypeReadonly. Returns the trendline type.
namestringReturns the name of the trendline.
ordernumberReturns or sets the trendline order (an integer greater than 1) when the trendline type is Polynomial. The order must be between 2 and 6.
periodnumberReturns or sets the period for the moving-average trendline.
forwardnumberReturns 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.
backwardnumberReturns 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
displayEquationbooleanRepresents 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.
displayRSquaredbooleanRepresents 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.
interceptnumberReturns or sets the point where the trendline crosses the value axis.
dataLabelsDataLabelsReadonly. Represents the DataLabels object for the specified series.
legendEntryLegendEntryReadonly. Gets the legend entry according to this trendline
compoundTypeMsoLineStyleSpecifies the compound line type
dashTypeMsoLineDashStyleSpecifies the dash line type
capTypeLineCapTypeSpecifies the ending caps.
joinTypeLineJoinTypeSpecifies the joining caps.
beginTypeMsoArrowheadStyleSpecifies an arrowhead for the begin of a line.
endTypeMsoArrowheadStyleSpecifies an arrowhead for the end of a line.
beginArrowLengthMsoArrowheadLengthSpecifies the length of the arrowhead for the begin of a line.
endArrowLengthMsoArrowheadLengthSpecifies the length of the arrowhead for the end of a line.
beginArrowWidthMsoArrowheadWidthSpecifies the width of the arrowhead for the begin of a line.
endArrowWidthMsoArrowheadWidthSpecifies the width of the arrowhead for the end of a line.
themeColorThemeColorGets and sets the theme color.
colorColorRepresents the Color of the line.
transparencynumberReturns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).
styleLineTypeRepresents the style of the line.
weightWeightTypeGets or sets the WeightType of the line.
weightPtnumberGets or sets the weight of the line in unit of points.
weightPxnumberGets or sets the weight of the line in unit of pixels.
formattingTypeChartLineFormattingTypeGets or sets format type.
isAutomaticColorbooleanReadonly. Indicates whether the color of line is automatic assigned.
isVisiblebooleanRepresents whether the line is visible.
isAutobooleanIndicates whether this line style is auto assigned.
gradientFillGradientFillReadonly. Represents gradient fill.

constructor(Line)

Constructs from a parent object convertible to this.

constructor(obj: Line);

Parameters:

ParameterTypeDescription
objLineThe parent object.

isNameAuto

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

isNameAuto : boolean;

type

Readonly. Returns the trendline type.

type : TrendlineType;

name

Returns the name of the trendline.

name : 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.

order : number;

period

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

period : number;

Remarks

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

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.

forward : number;

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

backward : number;

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.

displayEquation : boolean;

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.

displayRSquared : boolean;

intercept

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

intercept : number;

dataLabels

Readonly. Represents the DataLabels object for the specified series.

dataLabels : DataLabels;

legendEntry

Readonly. Gets the legend entry according to this trendline

legendEntry : LegendEntry;

compoundType

Specifies the compound line type

compoundType : MsoLineStyle;

dashType

Specifies the dash line type

dashType : MsoLineDashStyle;

capType

Specifies the ending caps.

capType : LineCapType;

joinType

Specifies the joining caps.

joinType : LineJoinType;

beginType

Specifies an arrowhead for the begin of a line.

beginType : MsoArrowheadStyle;

endType

Specifies an arrowhead for the end of a line.

endType : MsoArrowheadStyle;

beginArrowLength

Specifies the length of the arrowhead for the begin of a line.

beginArrowLength : MsoArrowheadLength;

endArrowLength

Specifies the length of the arrowhead for the end of a line.

endArrowLength : MsoArrowheadLength;

beginArrowWidth

Specifies the width of the arrowhead for the begin of a line.

beginArrowWidth : MsoArrowheadWidth;

endArrowWidth

Specifies the width of the arrowhead for the end of a line.

endArrowWidth : MsoArrowheadWidth;

themeColor

Gets and sets the theme color.

themeColor : ThemeColor;

Remarks

If the foreground color is not a theme color, NULL will be returned.

color

Represents the Color of the line.

color : Color;

transparency

Returns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).

transparency : number;

style

Represents the style of the line.

style : LineType;

weight

Gets or sets the WeightType of the line.

weight : WeightType;

weightPt

Gets or sets the weight of the line in unit of points.

weightPt : number;

weightPx

Gets or sets the weight of the line in unit of pixels.

weightPx : number;

formattingType

Gets or sets format type.

formattingType : ChartLineFormattingType;

isAutomaticColor

Readonly. Indicates whether the color of line is automatic assigned.

isAutomaticColor : boolean;

isVisible

Represents whether the line is visible.

isVisible : boolean;

isAuto

Indicates whether this line style is auto assigned.

isAuto : boolean;

gradientFill

Readonly. Represents gradient fill.

gradientFill : GradientFill;