When using compact number formatting (K, M, B) on chart axes, positive axis intervals are formatted correctly (e.g., 1.2K, 3.4M, 2.1B), but negative axis intervals display unformatted values (e.g., -1200, -3400000) instead of compact forms like -1.2K, -3.4M, or -2.1B. And this issue is occurring for both excel and ppt
Added aspose java programs below
Excel:
public static void main(String[] args) {
try {
// Create a new workbook
Workbook workbook = new Workbook();
// Get the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Add headers
cells.get("A1").setValue("Category");
cells.get("B1").setValue("Value");
// Sample data for waterfall chart
String[] categories = {"Start", "Q1 Growth", "Q2 Loss", "Q3 Growth", "Q4 Loss"};
double[] values = {-15000000, -2500000, 1800000, 32000000, -9500000};
// Populate data with compact formatting
for (int i = 0; i < categories.length; i++) {
cells.get(i + 2, 0).setValue(categories[i]);
cells.get(i + 2, 1).setValue(values[i]);
Style style = cells.get(i + 2, 1).getStyle();
style.setCustom("#,##0,,.0\"B\";[>=1000000]#,##0,.0\"M\";#,##0");
cells.get(i + 2, 1).setStyle(style);
}
// Create waterfall chart
int chartIndex = worksheet.getCharts().add(com.aspose.cells.ChartType.WATERFALL, 8, 2, 20, 12);
Chart chart = worksheet.getCharts().get(chartIndex);
// Set data range for chart
chart.getNSeries().add("B2:B7", true);
chart.getNSeries().setCategoryData("A2:A7");
// Configure chart appearance
chart.getTitle().setText("Simple Waterfall Chart");
chart.setShowLegend(false);
// Show data labels
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
// Configure Y-axis to use compact number formatting
Axis valueAxis = chart.getValueAxis();
valueAxis.getTickLabels().setNumberFormat("[>999999999]#.00,,,\"B\";[>999999] #.00,,\"M\"; #.00");
// Save the workbook
workbook.save("simple_waterfall_chart.xlsx", SaveFormat.XLSX);
System.out.println("Simple waterfall chart created successfully: waterfall_chart.xlsx");
} catch (Exception e) {
e.printStackTrace();
}
}
Ppt:
public static void main(String[] args) {
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Waterfall, 50, 50, 600, 400);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
// Clear default series/categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Sample categories
String[] cats = {"Previous Year", "January", "March", "August", "October", "Current Year"};
for (int i = 0; i < cats.length; i++) {
chart.getChartData().getCategories().add(wb.getCell(0, i + 1, 0, cats[i]));
}
// Sample values
double[] vals = {83222344.5, 112333333.5, -711111333.5, 2.5, 8.5, 3.5};
IChartSeries series = chart.getChartData().getSeries().add(wb.getCell(0, 0, 1, "Series1"), chart.getType());
for (int i = 0; i < vals.length; i++) {
IChartDataPoint dp = series.getDataPoints().addDataPointForWaterfallSeries(
wb.getCell(0, i + 1, 1, vals[i]));
if (i == 0 || i == vals.length - 1) {
dp.setSetAsTotal(true); // set endpoints as totals
}
}
// To Set Max and Min bound
IAxis yAxis = chart.getAxes().getVerticalAxis();
yAxis.setNumberFormat("[>999999999]#.00,,,\"B\";[>999999]#.00,,\"M\";#.00");
series.setShowConnectorLines(true);
pres.save("waterfall_slides.pptx", SaveFormat.Pptx);
pres.dispose();
}
waterfall-excel.png (18.5 KB)
waterfall-ppt.png (78.8 KB)
