Trendline class

Trendline class

Represents a trendline in a chart.

Inheritance: TrendlineLine

The Trendline type exposes the following members:

Properties

PropertyDescription
compound_typeSpecifies the compound line type
dash_typeSpecifies the dash line type
cap_typeSpecifies the ending caps.
join_typeSpecifies the joining caps.
begin_typeSpecifies an arrowhead for the begin of a line.
end_typeSpecifies an arrowhead for the end of a line.
begin_arrow_lengthSpecifies the length of the arrowhead for the begin of a line.
end_arrow_lengthSpecifies the length of the arrowhead for the end of a line.
begin_arrow_widthSpecifies the width of the arrowhead for the begin of a line.
end_arrow_widthSpecifies the width of the arrowhead for the end of a line.
theme_colorGets and sets the theme color.
colorRepresents the Color of the line.
transparencyReturns or sets the degree of transparency of the line as a value from 0.0 (opaque) through 1.0 (clear).
styleRepresents the style of the line.
weightGets or sets the WeightType of the line.
weight_ptGets or sets the weight of the line in unit of points.
weight_pxGets or sets the weight of the line in unit of pixels.
formatting_typeGets or sets format type.
is_automatic_colorIndicates whether the color of line is automatic assigned.
is_visibleRepresents whether the line is visible.
is_autoIndicates whether this line style is auto assigned.
gradient_fillRepresents gradient fill.
is_name_autoReturns if Microsoft Excel automatically determines the name of the trendline.
typeReturns the trendline type.
nameReturns the name of the trendline.
orderReturns or sets the trendline order (an integer greater than 1) when the trendline type is Polynomial.
The order must be between 2 and 6.
periodReturns or sets the period for the moving-average trendline.
forwardReturns 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.
backwardReturns 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
display_equationRepresents 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.
display_r_squaredRepresents 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.
interceptReturns or sets the point where the trendline crosses the value axis.
data_labelsRepresents the DataLabels object for the specified series.
legend_entryGets the legend entry according to this trendline

Example

from aspose.cells import Workbook
from aspose.cells.charts import ChartType, TrendlineType

# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding a sample value to "A1" cell
worksheet.cells.get("A1").put_value(50)
# Adding a sample value to "A2" cell
worksheet.cells.get("A2").put_value(100)
# Adding a sample value to "A3" cell
worksheet.cells.get("A3").put_value(150)
# Adding a sample value to "A4" cell
worksheet.cells.get("A4").put_value(200)
# Adding a sample value to "B1" cell
worksheet.cells.get("B1").put_value(60)
# Adding a sample value to "B2" cell
worksheet.cells.get("B2").put_value(32)
# Adding a sample value to "B3" cell
worksheet.cells.get("B3").put_value(50)
# Adding a sample value to "B4" cell
worksheet.cells.get("B4").put_value(40)
# Adding a sample value to "C1" cell as category data
worksheet.cells.get("C1").put_value("Q1")
# Adding a sample value to "C2" cell as category data
worksheet.cells.get("C2").put_value("Q2")
# Adding a sample value to "C3" cell as category data
worksheet.cells.get("C3").put_value("Y1")
# Adding a sample value to "C4" cell as category data
worksheet.cells.get("C4").put_value("Y2")
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.n_series.add("A1:B4", True)
# Setting the data source for the category data of NSeries
chart.n_series.category_data = "C1:C4"
# adding a linear trendline
index = chart.n_series[0].trend_lines.add(TrendlineType.LINEAR)
trendline = chart.n_series[0].trend_lines[index]
# Setting the custom name of the trendline.
trendline.name = "Linear"
# Displaying the equation on chart
trendline.display_equation = True
# Displaying the R-Squared value on chart
trendline.display_r_squared = True
# Saving the Excel file
workbook.save("book1.xls")

See Also