Waterfall chart Data labels are not getting removed

Hi Team,
In my Excel waterfall chart, I set the data labels to ‘Show Value = False’ for the series and for specific data points, but the labels are still displayed. How can I successfully remove these data labels.

Please find the Java 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", "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);
        }
        {
      	  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");
        }
        
        // Now disable data labels AFTER setting the format - this is critical!
        for (int i = 0; i< series.getPoints().getCount();i++)
        {
            series.getPoints().get(i).getDataLabels().setShowValue(false);
            series.getPoints().get(i).getDataLabels().setNumberFormatLinked(true);
        }
        
        // Also disable at series level
        chart.getNSeries().get(0).getDataLabels().setShowValue(false);
        
                 
        // 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();
    }
}

@Shivapriya

  1. In Aspose.Cells for Java, removing data labels from a waterfall chart requires setting ShowValue to false at both the series level and individual point level .
  2. The user’s code correctly attempts to disable data labels at both the series and point levels by calling setShowValue(false) .
  3. Setting NumberFormatLinked to true after setting the number format is a recommended practice to ensure proper label formatting and removal .

Your code already implements the correct approach by disabling data labels at both the series and point levels. However, if the labels are still visible, this might be due to a limitation or bug in the Aspose.Cells library when handling data labels in waterfall charts . We recommend testing with the latest version of Aspose.Cells for Java. If the issue persists, please contact Aspose support for further assistance. A minimal reproducible example has been provided in your original query .

@Shivapriya
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46623

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Shivapriya,

Since we already logged a ticket (“CELLSJAVA-46623” - The Waterfall chart data labels are not getting removed) and we will fix this issue soon. For the time being, you may try not to set show data labels’ values attribute and remove all data points of the series of the chart. See the updated sample code that works fine.

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);
        }
        {
      	  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);
        }

        // Clear the series data points
        series.getPoints().clear(); 
                         
        // 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();
    }
}

Hope, this helps a bit.

Thank you for your input.

I have tried your suggestion, but we have a requirement of showing colors on each datapoint in waterfall chart and if we apply the colors and then perform dataPoints().clear(); It is removing the colors applied on the datapoints.

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(false);
            chart.getNSeries().get(0).getPoints().clear();

            ChartPointCollection  chartPointCollection = chart.getNSeries().get(0).getPoints();
            for (int i = 0; i < chartPointCollection.getCount(); i++) {
                ChartPoint dataPoint = chartPointCollection.get(i);
                dataPoint.getArea().getFillFormat().setFillType(FillType.SOLID);
                // Example: set color to green, adjust as needed
                dataPoint.getArea().getFillFormat().getSolidFill().setColor(Color.getGreen());
            }
            chart.getNSeries().get(0).getPoints().clear();
            // Save the workbook
            workbook.save("simple_waterfall_chart.xlsx", SaveFormat.XLSX);
            System.out.println("Simple waterfall chart created successfully: simple_waterfall_chart.xlsx");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

@VaradS,

We are in the process to resolve the issue, so you don’t need to use the workaround (dataPoints().clear();) to cope with it in the long run. Once we fix the issue, we will update you here.

By the way, to cope with it as you want to retain the data points colors in the Waterfall chart, you may try the following code segment (instead). You may not set clearing data points at the end, i.e., remove the line at the end: chart.getNSeries().get(0).getPoints().clear();:

.....
// Show data labels
chart.getNSeries().get(0).getPoints().clear();

ChartPointCollection  chartPointCollection = chart.getNSeries().get(0).getPoints();
for (int i = 0; i < chartPointCollection.getCount(); i++) {
                ChartPoint dataPoint = chartPointCollection.get(i);
                dataPoint.getArea().getFillFormat().setFillType(FillType.SOLID);
                // Example: set color to green, adjust as needed
                dataPoint.getArea().getFillFormat().getSolidFill().setColor(Color.getGreen());
}

// Save the workbook
workbook.save("simple_waterfall_chart.xlsx", SaveFormat.XLSX);
System.out.println("Simple waterfall chart created successfully: simple_waterfall_chart.xlsx");

Let us know your feedback.

Hi @Shivapriya @VaradS
We optimized this issue and the file generated with your code after the optimization is as follows. It will be effective in version 26.2.
NewOutput.zip (10.0 KB)

Hi @leoluo ,

Thanks for resolving the issue.
As I’m not the owner of ticket, Is there a way I can access the optimized file you have uploaded?

@VaradS
I sent you a message in the forum, please check if you received it?

@VaradS,

Alternatively, you may post a new thread and ask for the attachment file (you may refer to or paste reference link of this thread) and we will share the optimized file in your (new) thread.

@amjad.sahi , @leoluo

Created a new thrad.

@VaradS,

Thanks for creating the new thread. We have provided the optimized file in your new thread.

The issues you have found earlier (filed as CELLSJAVA-46623) have been fixed in Aspose.Cells for Java 26.2.