获取图表趋势线的方程文本

示例

下图显示了有趋势线的图表,其方程文本以红色显示。我们将使用Trendline.getDataLabels().getText()属性来检索这个文本,在以下示例代码中。

todo:image_alt_text

获取图表趋势线的方程文本的Java代码

// 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());

由示例代码生成的输出

这是上述示例代码的控制台输出。

Equation Text: y = 8.1333x + 5