Read Axis Labels after Calculating the Chart with C++
Possible Usage Scenarios
You can read axis labels of your chart after calculating its values using the Chart.Calculate() method. Please use the Axis.GetAxisTexts() method for this purpose that will return the list of axis labels.
Read Axis Labels after Calculating the Chart
Please see the following sample code that loads the sample Excel file and reads the category axis labels of the chart in the first worksheet. It then prints the values of the axis labels on the console. Please see the console output of the sample code given below for a reference.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
Workbook wb(srcDir + u"ReadAxisLabels.xlsx");
Worksheet ws = wb.GetWorksheets().Get(0);
Chart ch = ws.GetCharts().Get(0);
ch.Calculate();
Vector<U16String> lstLabels = ch.GetCategoryAxis().GetAxisTexts();
std::wcout << L"Category Axis Labels: " << std::endl;
std::wcout << L"---------------------" << std::endl;
for (int32_t i = 0; i < lstLabels.GetLength(); ++i)
{
std::wcout << reinterpret_cast<const wchar_t*>(lstLabels[i].GetData()) << std::endl;
}
Aspose::Cells::Cleanup();
return 0;
}
Console Output
Category Axis Labels:
\---------------------
Iran
China
USA
Brazil
England