Get Equation Text of Chart Trendline with Node.js via C++
Contents
[
Hide
]
You can retrieve the Equation Text of Chart Trendline using Aspose.Cells for Node.js via C++. Aspose.Cells provides DataLabels.getText() property which returns the Equation Text of chart trendline. To make use of this property, you will first have to call Chart.calculate() method.
The following screenshot shows the Chart with a Trendline and its Equation Text is shown in Red color. We will retrieve this text using the DataLabels.getText() property in the following sample code.
Node.js code to get equation text of chart trendline
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());
Output generated by the sample code
This is the console output of the above sample code.
Equation Text: y = 8.1333x + 5