Excelチャートの軸の管理
Contents
[
Hide
]
Excelチャートには、3種類の軸があります。
- 水平(カテゴリ)軸:X軸
- 垂直(値)軸:Y軸
- 深度(シリーズ)軸:Z軸
軸オプション
Aspose.Cells は、Axis オブジェクトを使用して、実行時にチャートの軸を管理することもできます。このオブジェクトを使用すると、Excel で行うように、軸のすべてのオプションを変更することができます。
||
X軸とY軸を管理する
Excelチャートでは、水平軸と垂直軸が最も人気のある軸です。
次のコードスニペットは、X軸とY軸のオプションを設定する方法を示しています。
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
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook object | |
int sheetIndex = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding sample values to cells | |
worksheet.getCells().get("A1").putValue("Series1"); | |
worksheet.getCells().get("A2").putValue(50); | |
worksheet.getCells().get("A3").putValue(100); | |
worksheet.getCells().get("A4").putValue(150); | |
worksheet.getCells().get("B1").putValue("Series2"); | |
worksheet.getCells().get("B2").putValue(60); | |
worksheet.getCells().get("B3").putValue(32); | |
worksheet.getCells().get("B4").putValue(50); | |
// Adding a chart to the worksheet | |
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 15, 5); | |
// Accessing the instance of the newly added chart | |
Chart chart = worksheet.getCharts().get(chartIndex); | |
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.setChartDataRange("A1:B4",true); | |
//hiding X axis | |
chart.getCategoryAxis().setVisible(false); | |
// Setting max value of Y axis. | |
chart.getValueAxis().setMaxValue(200); | |
// Setting major unit. | |
chart.getValueAxis().setMajorUnit(50); | |
// Save the file | |
workbook.save("chart_axes.xlsx"); |