获取趋势线方程文本的Node.js示例代码
Contents
[
Hide
]
你可以使用Aspose.Cells for Node.js via C++检索图表趋势线的方程文本。Aspose.Cells提供了DataLabels.getText()属性,用于返回趋势线的方程文本,要使用这个属性,首先需要调用Chart.calculate()方法。
以下截图显示带有趋势线的图表及其方程文本(红色显示)。我们将在下面的示例代码中使用 DataLabels.getText() 属性检索这段文本。
使用Node.js获取图表趋势线的方程文本的代码示例
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create workbook object from source Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "source.xlsx"));
// Access the first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the worksheet
const chart = worksheet.getCharts().get(0);
// Calculate the Chart first to get the Equation Text of Trendline
chart.calculate();
// Access the Trendline
const trendLine = chart.getNSeries().get(0).getTrendLines().get(0);
// Read the Equation Text of Trendline
console.log("Equation Text: " + trendLine.getDataLabels().getText());
示例代码生成的输出
这是上述示例代码的控制台输出。
Equation Text: y = 8.1333x + 5