チャートの計算後に軸ラベルを読む
Contents
[
Hide
]
可能な使用シナリオ
軸ラベルの値を計算した後に、Chart.Calculate()メソッドを使用してチャートの軸ラベルを読み取ることができます。この目的のためには、リストはAxis.GetAxisTexts()メソッドを使用してください。
チャートを計算した後に軸ラベルを読み取る
次のサンプルコードは、サンプルExcelファイルを読み込み、最初のワークシートのチャートのカテゴリ軸ラベルを読み取ります。その後、軸ラベルの値をコンソールに出力します。参考のために、以下に示すサンプルコードのコンソール出力をご覧ください。
サンプルコード
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-.NET | |
//Load the Excel file containing chart | |
Workbook wb = new Workbook("ReadAxisLabels.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access the chart | |
Chart ch = ws.Charts[0]; | |
//Calculate the chart | |
ch.Calculate(); | |
//Read axis labels of category axis | |
string[] lstLabels = ch.CategoryAxis.GetAxisTexts(); | |
//Print axis labels on console | |
System.Console.WriteLine("Category Axis Labels: "); | |
System.Console.WriteLine("---------------------"); | |
//Iterate axis labels and print them one by one | |
for (int i = 0; i < lstLabels.Length; i++) | |
{ | |
System.Console.WriteLine(lstLabels[i]); | |
} | |
コンソール出力
Category Axis Labels:
\---------------------
Iran
China
USA
Brazil
England