Get Equation Text of Chart Trendline
Contents
[
Hide
]
You can retrieve the Equation Text of Chart Trendline using Aspose.Cells for Python via .NET. Aspose.Cells for Python via .NET provides property which returns the Equation Text of chart trendline. To make use of this property, you will first have to call Chart.calculate() method.
The following screenshot shows the Chart with a Trendline and its Equation Text is shown in Red color. We will retrieve this text using the Trendline.data_labels.text property in the following sample code.
C# code to get equation text of chart trendline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object from source Excel file | |
workbook = Workbook(dataDir + "source.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access the first chart inside the worksheet | |
chart = worksheet.charts[0] | |
# Calculate the Chart first to get the Equation Text of Trendline | |
chart.calculate() | |
# Access the Trendline | |
trendLine = chart.n_series[0].trend_lines[0] | |
# Read the Equation Text of Trendline | |
print("Equation Text: " + trendLine.data_labels.text) |
Output generated by the sample code
This is the console output of the above sample code.
Equation Text: y = 8.1333x + 5