Hi Team,
In Excel and ppt, Negative numbers are not appearing in a compact format in the tooltip. How can we ensure that negative values are displayed in compact format, and is it possible to modify the tooltip description too?
image.png (11.7 KB)
Please find the aspose program below
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 Test Label", "Q1 Growth Test Label X-axis 123456", "Q2 Loss Test Label X-axis 123456789", "Q3 Growth Test Label X-axis 123456", "Q4 Loss Test Label"};
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);
}
{
Style style = cells.get(1, 1).getStyle();
style.setCustom("#,##0,,.0\"B\";[>=1000000]#,##0,.0\"M\";#,##0");
cells.get(1, 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("B3:B7", true);
chart.getNSeries().setCategoryData("A3:A7");
// Configure chart appearance
chart.getTitle().setText("Simple Waterfall Chart");
chart.setShowLegend(false);
Series series = workbook.getWorksheets().get(0).getCharts().get(0).getNSeries().get(0);
chart.getValueAxis().getTickLabels().setNumberFormat("#,##0,,.0\"B\";[>=1000000]#,##0,.0\"M\";#,##0");
// Set number format for data labels first
for (int i = 0; i< series.getPoints().getCount();i++)
{
series.getPoints().get(i).getDataLabels().setNumberFormat("#,##0,,.0\"B\";[>=1000000]#,##0,.0\"M\";#,##0");
}
for (int i = 0; i< series.getPoints().getCount();i++)
{
series.getPoints().get(i).getDataLabels().setNumberFormatLinked(true);
}
chart.getCategoryAxis().getTickLabels().setRotationAngle(45);
// 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();
}
}