C++を通じてExcelチャートの軸を管理する
Contents
[
Hide
]
Excelチャートには、3種類の軸があります。
- 水平(カテゴリ)軸:X軸
- 垂直(値)軸:Y軸
- 深度(シリーズ)軸:Z軸
軸オプション
C++経由のAspose.Cells for JavaScriptは、ランタイム中にチャートの軸を管理することも可能です。 Axis オブジェクトを使用して、Excelと同様に軸のすべてのオプションを変更できます。
|
|
X軸とY軸を管理する
Excelのチャートでは、水平方向と垂直方向の軸が最も一般的に使用される軸です。
次のコードスニペットは、X軸とY軸のオプション設定方法を示しています。
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - Chart Axes</title>
</head>
<body>
<h1>Chart Axes Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, ChartType } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
// Instantiate a new Workbook
const workbook = new Workbook();
// Adding a new worksheet to the Workbook object
const sheetIndex = workbook.worksheets.add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
const worksheet = workbook.worksheets.get(sheetIndex);
// Adding sample values to cells
worksheet.cells.get("A1").value = "Series1";
worksheet.cells.get("A2").value = 50;
worksheet.cells.get("A3").value = 100;
worksheet.cells.get("A4").value = 150;
worksheet.cells.get("B1").value = "Series2";
worksheet.cells.get("B2").value = 60;
worksheet.cells.get("B3").value = 32;
worksheet.cells.get("B4").value = 50;
// Adding a chart to the worksheet
const chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
const chart = worksheet.charts.get(chartIndex);
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4"
chart.chartDataRange = ["A1:B4", true];
// Hiding X axis
chart.categoryAxis.isVisible = false;
// Setting max value of Y axis
chart.valueAxis.maxValue = 200;
// Setting major unit
chart.valueAxis.majorUnit = 50;
// Save the file and provide download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'chart_axes.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Workbook created successfully. Click the download link to download the file.</p>';
});
</script>
</html>