チャート トレンドラインの数式テキストを取得する
Contents
[
Hide
]
Aspose.Cells を使用して、チャート トレンドラインの数式テキストを取得できます。Aspose.Cells は提供しますTrendline.getDataLabels().getText()チャート トレンドラインの数式テキストを返すプロパティ。このプロパティを利用するには、最初に呼び出す必要があります[Chart.calculate()](https://reference.aspose.com/cells/java/com.aspose.cells/chart#calculate()) 方法。
例
次のスクリーンショットは、トレンドラインを含むチャートを示しており、その数式テキストは赤色で表示されています。このテキストを取得するには、Trendline.getDataLabels().getText()次のサンプル コードのプロパティ。
Java チャート トレンドラインの数式テキストを取得するコード
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()); |
サンプル コードによって生成される出力
これは、上記のサンプル コードのコンソール出力です。
Equation Text: y = 8.1333x + 5