C++を使ってティックラベルの向きを変更する

目盛りラベル方向の変更

Aspose.Cellsは、TickLabels.GetDirectionType()プロパティを使用してチャートのティックラベルの向きを変更する機能を提供します。TickLabels.GetDirectionType()プロパティはChartTextDirectionType列挙値を受け入れます。ChartTextDirectionType列挙には次のメンバーが含まれます:

- 水平 - 垂直 - Rotate90 - Rotate270 - スタック

以下の画像は、ソースファイルと出力ファイルを比較しています:

ソースファイル画像

todo:image_alt_text

出力ファイル画像

todo:image_alt_text

次のコードスニペットは、Rotate90から水平への目盛りラベルの方向を変更します。

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C

    // Directory source and output paths
    U16String sourceDir(u"..\\Data\\01_SourceDirectory\\");
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    // Create workbook and load the sample Excel file
    Workbook workbook(sourceDir + u"SampleChangeTickLabelDirection.xlsx");

    // Obtain the first worksheet
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Load the chart from the source worksheet
    Chart chart = worksheet.GetCharts().Get(0);

    // Set the category axis tick labels direction to Horizontal
    chart.GetCategoryAxis().GetTickLabels().SetDirectionType(ChartTextDirectionType::Horizontal);

    // Output the modified workbook to a new file
    workbook.Save(outDir + u"outputChangeChartDataLableDirection.xlsx");

    std::cout << "Chart tick label direction changed successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

ソースファイルと出力ファイルは、以下のリンクからダウンロードできます。

ソースファイル

出力ファイル