Obtener el texto de ecuación de la tendencia del gráfico
Contents
[
Hide
]
Puede recuperar el Texto de la Ecuación de la Línea de Tendencia del Gráfico utilizando Aspose.Cells. Aspose.Cells proporciona la propiedad Trendline.getDataLabels().getText() que devuelve el Texto de la Ecuación de la línea de tendencia del gráfico. Para hacer uso de esta propiedad, primero deberá llamar al método Chart.calculate().
Ejemplo
La siguiente captura de pantalla muestra el gráfico con una línea de tendencia y su Texto de la Ecuación se muestra en color rojo. Recuperaremos este texto usando la propiedad Trendline.getDataLabels().getText() en el siguiente código de ejemplo.
Código en Java para obtener el texto de la ecuación de la línea de tendencia del gráfico
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()); |
Salida generada por el código de ejemplo
Este es el resultado de consola del código de ejemplo anterior.
Equation Text: y = 8.1333x + 5