Ottieni il Testo dell Equazione della Retta di Tendenza del Grafico

Lo screenshot seguente mostra il grafico con una retta di tendenza e il suo testo dell’equazione è mostrato in rosso. Recupereremo questo testo utilizzando la proprietà Trendline.data_labels.text nel seguente codice di esempio.

todo:image_alt_text

Codice C# per ottenere il testo dell’equazione della retta di tendenza

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 generato dal codice di esempio

Questo è l’output console del codice di esempio precedente.

Equation Text: y = 8.1333x + 5