Trendline

Trendline class

Represents a trendline in a chart.

class Trendline extends Line;

Example

const { Workbook, ChartType, TrendlineType } = require("aspose.cells.node");

//Instantiating a Workbook object
var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.getWorksheets().add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.getWorksheets().get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.getCells().get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.getCells().get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.getCells().get("A3").putValue(150);
//Adding a sample value to "A4" cell
worksheet.getCells().get("A4").putValue(200);
//Adding a sample value to "B1" cell
worksheet.getCells().get("B1").putValue(60);
//Adding a sample value to "B2" cell
worksheet.getCells().get("B2").putValue(32);
//Adding a sample value to "B3" cell
worksheet.getCells().get("B3").putValue(50);
//Adding a sample value to "B4" cell
worksheet.getCells().get("B4").putValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.getCells().get("C1").putValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.getCells().get("C2").putValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.getCells().get("C3").putValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.getCells().get("C4").putValue("Y2");
//Adding a chart to the worksheet
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.getCharts().get(chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.getNSeries().add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.getNSeries().setCategoryData("C1:C4");
//adding a linear trendline
var index = chart.getNSeries().get(0).getTrendLines().add(TrendlineType.Linear);
var trendline = chart.getNSeries().get(0).getTrendLines().get(index);
//Setting the custom name of the trendline.
trendline.setName("Linear");
//Displaying the equation on chart
trendline.setDisplayEquation(true);
//Displaying the R-Squared value on chart
trendline.setDisplayRSquared(true);
//Saving the Excel file
workbook.save("output/ChartsTrendline.xls");

Constructors

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

Methods

MethodDescription
isNameAuto()Returns if Microsoft Excel automatically determines the name of the trendline.
setIsNameAuto(boolean)Returns if Microsoft Excel automatically determines the name of the trendline.
getType()Returns the trendline type.
getName()Returns the name of the trendline.
setName(string)Returns the name of the trendline.
getOrder()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.
setOrder(number)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.
getPeriod()Returns or sets the period for the moving-average trendline.
setPeriod(number)Returns or sets the period for the moving-average trendline.
getForward()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.
setForward(number)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.
getBackward()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
setBackward(number)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
getDisplayEquation()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.
setDisplayEquation(boolean)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.
getDisplayRSquared()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.
setDisplayRSquared(boolean)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.
getIntercept()Returns or sets the point where the trendline crosses the value axis.
setIntercept(number)Returns or sets the point where the trendline crosses the value axis.
getDataLabels()Represents the DataLabels object for the specified series.
getLegendEntry()Gets the legend entry according to this trendline
isNull()Checks whether the implementation object is null.
getCompoundType()Specifies the compound line type
setCompoundType(MsoLineStyle)Specifies the compound line type
getDashType()Specifies the dash line type
setDashType(MsoLineDashStyle)Specifies the dash line type
getCapType()Specifies the ending caps.
setCapType(LineCapType)Specifies the ending caps.
getJoinType()Specifies the joining caps.
setJoinType(LineJoinType)Specifies the joining caps.
getBeginType()Specifies an arrowhead for the begin of a line.
setBeginType(MsoArrowheadStyle)Specifies an arrowhead for the begin of a line.
getEndType()Specifies an arrowhead for the end of a line.
setEndType(MsoArrowheadStyle)Specifies an arrowhead for the end of a line.
getBeginArrowLength()Specifies the length of the arrowhead for the begin of a line.
setBeginArrowLength(MsoArrowheadLength)Specifies the length of the arrowhead for the begin of a line.
getEndArrowLength()Specifies the length of the arrowhead for the end of a line.
setEndArrowLength(MsoArrowheadLength)Specifies the length of the arrowhead for the end of a line.
getBeginArrowWidth()Specifies the width of the arrowhead for the begin of a line.
setBeginArrowWidth(MsoArrowheadWidth)Specifies the width of the arrowhead for the begin of a line.
getEndArrowWidth()Specifies the width of the arrowhead for the end of a line.
setEndArrowWidth(MsoArrowheadWidth)Specifies the width of the arrowhead for the end of a line.
getThemeColor()Gets and sets the theme color.
setThemeColor(ThemeColor)Gets and sets the theme color.
getColor()Represents the Color of the line.
setColor(Color)Represents the Color of the line.
getTransparency()Returns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).
setTransparency(number)Returns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).
getStyle()Represents the style of the line.
setStyle(LineType)Represents the style of the line.
getWeight()Gets or sets the WeightType of the line.
setWeight(WeightType)Gets or sets the WeightType of the line.
getWeightPt()Gets or sets the weight of the line in unit of points.
setWeightPt(number)Gets or sets the weight of the line in unit of points.
getWeightPx()Gets or sets the weight of the line in unit of pixels.
setWeightPx(number)Gets or sets the weight of the line in unit of pixels.
getFormattingType()Gets or sets format type.
setFormattingType(ChartLineFormattingType)Gets or sets format type.
isAutomaticColor()Indicates whether the color of line is automatic assigned.
isVisible()Represents whether the line is visible.
setIsVisible(boolean)Represents whether the line is visible.
isAuto()Indicates whether this line style is auto assigned.
setIsAuto(boolean)Indicates whether this line style is auto assigned.
getGradientFill()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;

setIsNameAuto(boolean)

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

setIsNameAuto(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

getType()

Returns the trendline type.

getType() : TrendlineType;

Returns

TrendlineType

getName()

Returns the name of the trendline.

getName() : string;

setName(string)

Returns the name of the trendline.

setName(value: string) : void;

Parameters:

ParameterTypeDescription
valuestringThe value to set.

getOrder()

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.

getOrder() : number;

setOrder(number)

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.

setOrder(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getPeriod()

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

getPeriod() : 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

setPeriod(number)

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

setPeriod(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

Remarks

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

getForward()

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.

getForward() : number;

setForward(number)

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.

setForward(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getBackward()

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

getBackward() : number;

setBackward(number)

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

setBackward(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getDisplayEquation()

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.

getDisplayEquation() : boolean;

setDisplayEquation(boolean)

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.

setDisplayEquation(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

getDisplayRSquared()

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.

getDisplayRSquared() : boolean;

setDisplayRSquared(boolean)

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.

setDisplayRSquared(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

getIntercept()

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

getIntercept() : number;

setIntercept(number)

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

setIntercept(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getDataLabels()

Represents the DataLabels object for the specified series.

getDataLabels() : DataLabels;

Returns

DataLabels

getLegendEntry()

Gets the legend entry according to this trendline

getLegendEntry() : LegendEntry;

Returns

LegendEntry

isNull()

Checks whether the implementation object is null.

isNull() : boolean;

getCompoundType()

Specifies the compound line type

getCompoundType() : MsoLineStyle;

Returns

MsoLineStyle

setCompoundType(MsoLineStyle)

Specifies the compound line type

setCompoundType(value: MsoLineStyle) : void;

Parameters:

ParameterTypeDescription
valueMsoLineStyleThe value to set.

getDashType()

Specifies the dash line type

getDashType() : MsoLineDashStyle;

Returns

MsoLineDashStyle

setDashType(MsoLineDashStyle)

Specifies the dash line type

setDashType(value: MsoLineDashStyle) : void;

Parameters:

ParameterTypeDescription
valueMsoLineDashStyleThe value to set.

getCapType()

Specifies the ending caps.

getCapType() : LineCapType;

Returns

LineCapType

setCapType(LineCapType)

Specifies the ending caps.

setCapType(value: LineCapType) : void;

Parameters:

ParameterTypeDescription
valueLineCapTypeThe value to set.

getJoinType()

Specifies the joining caps.

getJoinType() : LineJoinType;

Returns

LineJoinType

setJoinType(LineJoinType)

Specifies the joining caps.

setJoinType(value: LineJoinType) : void;

Parameters:

ParameterTypeDescription
valueLineJoinTypeThe value to set.

getBeginType()

Specifies an arrowhead for the begin of a line.

getBeginType() : MsoArrowheadStyle;

Returns

MsoArrowheadStyle

setBeginType(MsoArrowheadStyle)

Specifies an arrowhead for the begin of a line.

setBeginType(value: MsoArrowheadStyle) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadStyleThe value to set.

getEndType()

Specifies an arrowhead for the end of a line.

getEndType() : MsoArrowheadStyle;

Returns

MsoArrowheadStyle

setEndType(MsoArrowheadStyle)

Specifies an arrowhead for the end of a line.

setEndType(value: MsoArrowheadStyle) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadStyleThe value to set.

getBeginArrowLength()

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

getBeginArrowLength() : MsoArrowheadLength;

Returns

MsoArrowheadLength

setBeginArrowLength(MsoArrowheadLength)

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

setBeginArrowLength(value: MsoArrowheadLength) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadLengthThe value to set.

getEndArrowLength()

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

getEndArrowLength() : MsoArrowheadLength;

Returns

MsoArrowheadLength

setEndArrowLength(MsoArrowheadLength)

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

setEndArrowLength(value: MsoArrowheadLength) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadLengthThe value to set.

getBeginArrowWidth()

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

getBeginArrowWidth() : MsoArrowheadWidth;

Returns

MsoArrowheadWidth

setBeginArrowWidth(MsoArrowheadWidth)

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

setBeginArrowWidth(value: MsoArrowheadWidth) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadWidthThe value to set.

getEndArrowWidth()

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

getEndArrowWidth() : MsoArrowheadWidth;

Returns

MsoArrowheadWidth

setEndArrowWidth(MsoArrowheadWidth)

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

setEndArrowWidth(value: MsoArrowheadWidth) : void;

Parameters:

ParameterTypeDescription
valueMsoArrowheadWidthThe value to set.

getThemeColor()

Gets and sets the theme color.

getThemeColor() : ThemeColor;

Returns

ThemeColor

Remarks

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

setThemeColor(ThemeColor)

Gets and sets the theme color.

setThemeColor(value: ThemeColor) : void;

Parameters:

ParameterTypeDescription
valueThemeColorThe value to set.

Remarks

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

getColor()

Represents the Color of the line.

getColor() : Color;

Returns

Color

setColor(Color)

Represents the Color of the line.

setColor(value: Color) : void;

Parameters:

ParameterTypeDescription
valueColorThe value to set.

getTransparency()

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

getTransparency() : number;

setTransparency(number)

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

setTransparency(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getStyle()

Represents the style of the line.

getStyle() : LineType;

Returns

LineType

setStyle(LineType)

Represents the style of the line.

setStyle(value: LineType) : void;

Parameters:

ParameterTypeDescription
valueLineTypeThe value to set.

getWeight()

Gets or sets the WeightType of the line.

getWeight() : WeightType;

Returns

WeightType

setWeight(WeightType)

Gets or sets the WeightType of the line.

setWeight(value: WeightType) : void;

Parameters:

ParameterTypeDescription
valueWeightTypeThe value to set.

getWeightPt()

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

getWeightPt() : number;

setWeightPt(number)

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

setWeightPt(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getWeightPx()

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

getWeightPx() : number;

setWeightPx(number)

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

setWeightPx(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getFormattingType()

Gets or sets format type.

getFormattingType() : ChartLineFormattingType;

Returns

ChartLineFormattingType

setFormattingType(ChartLineFormattingType)

Gets or sets format type.

setFormattingType(value: ChartLineFormattingType) : void;

Parameters:

ParameterTypeDescription
valueChartLineFormattingTypeThe value to set.

isAutomaticColor()

Indicates whether the color of line is automatic assigned.

isAutomaticColor() : boolean;

isVisible()

Represents whether the line is visible.

isVisible() : boolean;

setIsVisible(boolean)

Represents whether the line is visible.

setIsVisible(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

isAuto()

Indicates whether this line style is auto assigned.

isAuto() : boolean;

setIsAuto(boolean)

Indicates whether this line style is auto assigned.

setIsAuto(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

getGradientFill()

Represents gradient fill.

getGradientFill() : GradientFill;

Returns

GradientFill