チャートの軸ラベルを計算後に読む方法:Node.js経由のC++
Contents
[
Hide
]
可能な使用シナリオ
チャートの値を計算した後、軸ラベルを読み取るにはChart.calculate()メソッドを使用します。この目的のために、Axis.getAxisTexts()メソッドを利用してください。これにより軸ラベルのリストが返されます。
チャートを計算した後に軸ラベルを読み取る
次のサンプルコードは、サンプルExcelファイルを読み込み、最初のワークシートのチャートのカテゴリ軸ラベルを読み取ります。その後、軸ラベルの値をコンソールに出力します。参考のために、以下に示すサンプルコードのコンソール出力をご覧ください。
サンプルコード
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "ReadAxisLabels_new.xlsx");
// Load the Excel file containing chart
const workbook = new AsposeCells.Workbook(filePath);
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Access the chart
const chart = worksheet.getCharts().get(0);
// Calculate the chart
chart.calculate();
// Read axis labels of category axis
const lstLabels = chart.getCategoryAxis().getAxisTexts();
// Print axis labels on console
console.log("Category Axis Labels: ");
console.log("---------------------");
// Iterate axis labels and print them one by one
for (let i = 0; i < lstLabels.length; i++) {
console.log(lstLabels[i]);
}
コンソール出力
Category Axis Labels:
\---------------------
Iran
China
USA
Brazil
England