获取图表趋势线的方程文本
Contents
[
Hide
]
您可以使用Aspose.Cells检索图表趋势线的方程文本。Aspose.Cells提供了Trendline.DataLabels.Text属性,该属性返回图表趋势线的方程文本。要使用此属性,您首先必须调用Chart.Calculate()方法。
下图显示了有趋势线的图表,其方程文本以红色显示。我们将使用Trendline.DataLabels.Text属性来检索这个文本,在以下示例代码中。
获取图表趋势线的方程文本的C#代码
This file contains hidden or 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Calculate the Chart first to get the Equation Text of Trendline | |
chart.Calculate(); | |
// Access the Trendline | |
Trendline trendLine = chart.NSeries[0].TrendLines[0]; | |
// Read the Equation Text of Trendline | |
Console.WriteLine("Equation Text: " + trendLine.DataLabels.Text); |
示例代码生成的输出
这是上述示例代码的控制台输出。
Equation Text: y = 8.1333x + 5