C++でチャートトレンドラインの方程式テキストを取得する方法
Contents
[
Hide
]
Aspose.Cellsを使用して、チャートのトレンドラインの方程式テキストを取得できます。Aspose.Cellsは、チャートのトレンドラインの方程式テキストを返すTrendline.GetText()プロパティを提供しています。このプロパティを利用するには、まずChart.Calculate()メソッドを呼び出す必要があります。
以下のスクリーンショットは、トレンドライン付きのチャートと、その式テキストが赤色で表示されたものです。この式テキストは、以下のサンプルコードの Trendline.GetText() プロパティを使用して取得します。
C++コードでチャートトレンドラインの方程式テキストを取得する方法
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create workbook object from source Excel file
Workbook workbook(srcDir + u"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
std::cout << "Equation Text: " << trendLine.GetDataLabels().GetText().ToUtf8() << std::endl;
Aspose::Cells::Cleanup();
}
サンプルコードによって生成された出力
これは上記のサンプルコードのコンソール出力です。
Equation Text: y = 8.1333x + 5