Ottieni il testo dell'equazione della linea di tendenza del grafico
Contents
[
Hide
]
È possibile recuperare il testo dell’equazione della linea di tendenza del grafico utilizzando Aspose.Cells. Aspose.Cells fornisceTrendline.DataLabels.Text proprietà che restituisce il testo dell’equazione della linea di tendenza del grafico. Per usufruire di questa proprietà, dovrai prima chiamareGrafico.Calcola() metodo.
La seguente schermata mostra il grafico con una linea di tendenza e il suo testo dell’equazione è mostrato in colore rosso. Recupereremo questo testo utilizzando il fileTrendline.DataLabels.Textproperty nel codice di esempio seguente.
C# codice per ottenere il testo dell’equazione della linea di tendenza del grafico
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Calculate the Chart first to get the Equation Text of Trendline | |
chart.Calculate(); | |
// Access the Trendline | |
Trendline trendLine = chart.NSeries[0].TrendLines[0]; | |
// Read the Equation Text of Trendline | |
Console.WriteLine("Equation Text: " + trendLine.DataLabels.Text); |
Output generato dal codice di esempio
Questo è l’output della console del codice di esempio precedente.
Equation Text: y = 8.1333x + 5