How to add the treemap chart in Excel

Hello,

Need help in creating a treemap chart similar to that attached Excel using Aspose.Cells for Java API.
Also, we need to make the labels as center-aligned.
Attached is a sample Excel file with the manually created chart.
Test-Treemap.zip (10.2 KB)

Thanks in Advance

@SrideviG
Please refer to the following document for creating a treemap chart.

The Java sample code is as follows:

// Create an instance of Workbook
Workbook workbook = new Workbook(filePath + "treemap.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Add a Treemap chart
int index = worksheet.getCharts().add(ChartType.TREEMAP, 5, 6, 20, 12);
// Retrieve the Chart object
Chart chart = worksheet.getCharts().get(index);
// Set the legend can be showed
chart.setShowLegend(true);
// Set the chart title name 
chart.getTitle().setText("TreeMap Chart");
// Add series data range(D2:D13,actually)
chart.getNSeries().add("D2:F13", true);
// Set category data(A2:A13 is incorrect )
chart.getNSeries().setCategoryData("A2:C13");
// Show the DataLabels with category names
chart.getNSeries().get(0).getDataLabels().setShowCategoryName(true);
// Fill the PlotArea area with nothing 
chart.getPlotArea().getArea().getFillFormat().setFillType(FillType.NONE);
// Save the Excel file
workbook.save(filePath + "out.xlsx");

Hope helps a bit.

@SrideviG
Regarding your requirements, you can use the following code to achieve your goals. Please refer to the attachment (71.4 KB).

The sample code as follows:

// Create an instance of Workbook
Workbook workbook = new Workbook(filePath + "Test-Treemap.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Add a Treemap chart
int index = worksheet.getCharts().add(ChartType.TREEMAP, 20, 5, 35, 12);
// Retrieve the Chart object
Chart chart = worksheet.getCharts().get(index);
// Set the legend can be showed
chart.setShowLegend(true);
// Set the chart title name 
chart.getTitle().setText("TreeMap Chart");
// Add series data range(D1:D8,actually)
chart.getNSeries().add("D1:D8", true);
// Set category data(A1:C8 is incorrect )
chart.getNSeries().setCategoryData("A1:C8");
// Show the DataLabels with category names
chart.getNSeries().get(0).getDataLabels().setShowCategoryName(true);

chart.getNSeries().get(0).getDataLabels().getFont().setColor(Color.getWhite());
// Fill the PlotArea area with nothing 
chart.getPlotArea().getArea().getFillFormat().setFillType(FillType.NONE);
// Save the Excel file
workbook.save(filePath + "out_java.xlsx");

PdfSaveOptions options = new PdfSaveOptions();
options.setOnePagePerSheet(true);
workbook.save(filePath + "out_java.pdf", options);

Hope helps a bit.

@SrideviG
Through further testing, it was found that after adding the treemap chart, there was a crash issue when opening it using Office 365.

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-45680

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.

@SrideviG,

We are pleased to inform you that your issue (logged as “CELLSJAVA-45680”) has been resolved. The fix will be included in our upcoming release (Aspose.Cells v23.11), We will release the version in this release. The release is planned for this week and you will be notified when the new version is released.

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