We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to set Custom Number Format for Y Axis Value of Excel Chart using Java

Hi Aspose Team,

I’m trying to set custom number format options for y axis value (using axis options), i.e., the Category as custom and change the Type using Aspose.Cells for Java API.
Please find attached screenshot below for your reference.
screenshot-newtab-2021.10.19-18_54_13.png (19.6 KB)

Could you please help me in achieving it?



Aspose.Cells does support to set custom number format for x or y axis value of the chart in Excel XLSX files. You can use TickLabels.setNumberFormat attribute to set to your desired custom number formatting string for your needs. See the steps details with sample code for your reference.

Steps to set Custom Number Format for Y Axis value using Java

  1. Add reference to maven repos. Aspose.Cells library in the project
  2. Import Workbook, Worksheet and other required classes in your program or import all the classes from com.aspose.cells package
  3. Fill data (for chart data source) into the newly added worksheet in the workbook
  4. Create a chart for example, a line chart using relevant APIs
  5. Set chart data series and category data
  6. Set custom number format for y axis value tick labels
  7. Save the workbook containing the chart with data

Sample code to set Custom Number Format for Y Axis value using Java

import com.aspose.cells.*;

        //Instantiate a new Workbook
        Workbook workbook = new Workbook();
        //Remove the existing (default) worksheet

        //Add a new sheet to the workbook
        Worksheet worksheet = workbook.getWorksheets().add("MySheet1");

        //Instantiate Random object
        Random rnd = new Random();

        final int mNum = 100 * 12 * 31;

        //Fill the two columns with some values
        int valNumber = 5;
        for (int i = 0; i < valNumber; i++)

            worksheet.getCells().get(i, 0).putValue(LocalDate.now().minusDays(new Random().nextInt(mNum)));
            worksheet.getCells().get(i, 1).putValue(rnd.nextInt(99999999) + 9999999);

        //Add a line chart to the sheet
        Chart chart = worksheet.getCharts().get(worksheet.getCharts().add(ChartType.LINE, 1, 5, 31, 25));

        //Set chart series data
        chart.getNSeries().add("B1:B5", true);
        //Set Category data

        //Set Category axis type and unit scale

        //Set custom number format for y axis value labels
        //Set custom number format for x axis value labels
        //Set rotation angle

        //Save the Excel file