Trendline类

Trendline类

表示图表中的趋势线。

遗产: TrendlineLine

Trendline 类型公开以下成员:

特性

属性描述
compound_type指定复合线类型
dash_type指定虚线类型
cap_type指定结束大写字母。
join_type指定连接帽。
begin_type指定行首的箭头。
end_type指定行尾的箭头。
begin_arrow_length指定行首的箭头长度。
end_arrow_length指定线末端箭头的长度。
begin_arrow_width指定线条开头的箭头宽度。
end_arrow_width指定线末端箭头的宽度。
theme_color获取和设置主题颜色。
color代表线条的颜色。
transparency返回或设置线条的透明度,其值范围为 0.0(不透明)到 1.0(透明)。
style代表线条的风格。
weight获取或设置线路的 WeightType
weight_pt获取或设置以点为单位的线的粗细。
weight_px获取或设置线条的粗细(以像素为单位)。
formatting_type获取或设置格式类型。
is_automatic_color指示线条颜色是否自动指定。
is_visible表示该线是否可见。
is_auto指示此线型是否自动分配。
gradient_fill代表渐变填充。
is_name_auto如果 Microsoft Excel 自动确定趋势线的名称,则返回。
type返回趋势线类型。
name返回趋势线的名称。
order当趋势线类型为多项式时,返回或设置趋势线阶数(大于 1 的整数)。
顺序必须在 2 到 6 之间。
period返回或设置移动平均趋势线的周期。
forward返回或设置趋势线向前延伸的周期数(或散点图上的单位数)。
周期数必须大于或等于零。
backward返回或设置趋势线向后延伸的周期数(或散点图上的单位数)。
周期数必须大于或等于零。
如果图表类型为柱形图,则周期数必须介于 0 到 0.5 之间
display_equation表示趋势线方程是否显示在图表上(与 R 平方值位于同一数据标签中)。将此属性设置为 True 会自动打开数据标签。
display_r_squared表示趋势线的 R 平方值是否显示在图表上(与方程位于同一数据标签中)。将此属性设置为 True 会自动打开数据标签。
intercept返回或设置趋势线与数值轴的交叉点。
data_labels表示指定系列的 DataLabels 对象。
legend_entry根据这条趋势线获取图例条目

例子

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")

也可以看看