Hämta ekvations text av diagramtrendlinje
Contents
[
Hide
]
Du kan hämta ekvationstexten för lutningslinjen i ett diagram med Aspose.Cells för Python via .NET. Aspose.Cells för Python via .NET tillhandahåller en egenskap som returnerar ekvationen för lutningslinjen i diagrammet. För att använda denna egenskap måste du först anropa Chart.calculate() metoden.
Följande skärmbild visar diagrammet med en trendlinje och dess ekvations text visas i rött. Vi kommer att hämta denna text med hjälp av egenskapen Trendline.data_labels.text i följande provkod.
C#-kod för att få ekvationstexten för diagramtrendlinje
This file contains hidden or 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) |
Utdata genererad av provkoden
Detta är konsoloutputen för ovanstående exempelkod.
Equation Text: y = 8.1333x + 5