如何通过 C++ 使用 JavaScript 创建柱状图
Contents
[
Hide
]
介绍
龙卷风图表,也称为龙卷风图或龙卷风图,是一种常用于Excel中的敏感性分析的数据可视化类型。它帮助您理解变量变化对特定结果或结果的影响。
如何在Excel中创建龙卷风图表
您可以通过以下步骤在Excel中创建龙卷风图表:
- 选择数据并转到插入 –> 图表 –> 插入柱状图或条形图 –> 堆积柱状图。点击。

- 更改Y轴:右键单击Y轴。点击格式轴。在标签中,点击标签位置下拉菜单并选择低项。

- 选择任何柱并进行格式设置。设置适当的间距宽度。

- 让我们从龙卷风图表中删除减号(-)。选择X轴。转到格式设置。在轴选项中,点击数字。在类别中,选择自定义。在格式代码中写入###0,###0。点击添加。

- 点击Y轴并转到轴选项。在轴选项中,勾选倒序显示的类别。

如何在 C++ 中使用 Aspose.Cells for JavaScript 添加柱状图
请参阅以下示例代码。它加载包含一些示例数据的示例Excel文件。然后根据初始数据创建堆叠条形图表,并设置相关属性。最后,将工作簿保存到输出XLSX格式。以下截图显示了Aspose.Cells在输出Excel文件中创建的龙卷风图表。

示例代码
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells Example</h1>
<input type="file" id="fileInput" accept=".xlsx" />
<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 } = 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');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Accessing the first worksheet in the Excel file
const sheet = workbook.worksheets.get(0);
const charts = sheet.charts;
// Add bar chart
const index = charts.add(AsposeCells.ChartType.BarStacked, 8, 1, 24, 8);
const chart = charts.get(index);
// Set data for bar chart
chart.chartDataRange = "A1:C7";
// Set properties for bar chart
chart.title.text = "Tornado chart";
chart.style = 2;
chart.plotArea.area.foregroundColor = AsposeCells.Color.White;
chart.plotArea.border.color = AsposeCells.Color.White;
chart.legend.position = AsposeCells.LegendPositionType.Bottom;
chart.categoryAxis.tickLabelPosition = AsposeCells.TickLabelPositionType.Low;
chart.category```html
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells Example</h1>
<input type="file" id="fileInput" accept=".xlsx" />
<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 } = 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');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Accessing the first worksheet in the Excel file
const sheet = workbook.worksheets.get(0);
const charts = sheet.charts;
// Add bar chart
const index = charts.add(AsposeCells.ChartType.BarStacked, 8, 1, 24, 8);
const chart = charts.get(index);
// Set data for bar chart
chart.chartDataRange = "A1:C7";
// Set properties for bar chart
chart.title.text = "Tornado chart";
chart.style = 2;
chart.plotArea.area.foregroundColor = AsposeCells.Color.White;
chart.plotArea.border.color = AsposeCells.Color.White;
chart.legend.position = AsposeCells.LegendPositionType.Bottom;
chart.categoryAxis.tickLabelPosition = AsposeCells.TickLabelPositionType.Low;
chart.categoryAxis.isPlotOrderReversed = true;
chart.gapWidth = 10;
const valueAxis = chart.valueAxis;
valueAxis.tickLabels.numberFormat = "#,##0;#,##0";
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
resultDiv.innerHTML = '<p style="color: green;">Operation completed successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>