Enable Compact Format for Negative Values in Tooltip

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

@Shivapriya

You’d like negative numbers to show in compact format in the chart tooltip and are wondering whether the tooltip text itself can be customized.

To help you further, could you let us know:

  • Which version of Aspose.Cells for Java you are using.
  • Whether you need only the number format changed for the tooltip, or you also want to add custom text (e.g., a prefix or suffix) to the tooltip description.

Once we have this information we can provide a more precise solution in this thread.

@Shivapriya,

Do you mean you want tooltips to be shown negative original values, e.g., -15000000, -2500000, -9500000, etc.? If true, please do not set the custom numbers formatting to the values in the cells. For example, you may comment out the lines of code for getting/setting styles to the cells:

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

You cannot modify the tooltip text directly. In case you still need to accomplish something else, kindly share a sample Excel file containing your Waterfall chart intact, where negative numbers formatting is in your desired compact form. We will check and look into it soon.

@Shivapriya,
Regarding Aspose.Slides, please provide a presentation file with a chart with the desired look. We will do our best to assist you in achieving the same result. Please note that tooltips are part of the PowerPoint UI and cannot be modified.