チャートの計算後に軸ラベルを読む

可能な使用シナリオ

チャートの値を計算した後に、軸ラベルを読み取る場合は、Chart.calculate()メソッドを使用します。これにより、軸ラベルのリストが返されます。

チャートを計算した後に軸ラベルを読み取る

次のサンプルコードでは、読み込み{0}し、ワークシートの最初のチャートのカテゴリ軸ラベルを読み取ります。その後、コンソールに軸ラベルの値を出力します。参考のため、次のサンプルコードのコンソール出力を参照してください。

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the Excel file containing chart
Workbook wb = new Workbook("64716829.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access the chart
Chart ch = ws.getCharts().get(0);
//Calculate the chart
ch.calculate();
//Read axis labels of category axis
String[] lstLabels = ch.getCategoryAxis().getAxisTexts();
//Print axis labels on console
System.out.println("Category Axis Labels: ");
System.out.println("---------------------");
//Iterate axis labels and print them one by one
for(int i=0; i<lstLabels.length; i++)
{
System.out.println(lstLabels[i]);
}

コンソール出力

 Category Axis Labels:

\---------------------

Iran

China

USA

Brazil

England