Ottieni il Testo dell Equazione della Retta di Tendenza del Grafico
Contents
[
Hide
]
È possibile recuperare il Testo dell’Equazione della Retta di Tendenza utilizzando Aspose.Cells. Aspose.Cells fornisce proprietà Trendline.getDataLabels().getText() che restituisce il testo dell’equazione della retta di tendenza. Per utilizzare questa proprietà, sarà prima necessario chiamare il metodo Chart.calculate().
Esempio
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.getDataLabels().getText() nel seguente codice di esempio.
Codice Java 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetWorksheetOfChart.class); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first chart inside the worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Calculate the Chart first to get the Equation Text of Trendline | |
chart.calculate(); | |
// Access the Trendline | |
Trendline trendLine = chart.getNSeries().get(0).getTrendLines().get(0); | |
// Read the Equation Text of Trendline | |
System.out.println("Equation Text: " + trendLine.getDataLabels().getText()); |
Output generato dal codice di esempio
Questo è l’output console del codice di esempio precedente.
Equation Text: y = 8.1333x + 5