TreeMap is a chart type used to display hierarchical data as a set of nested rectangles. Treemap charts are used to represent hierarchical data in a tree-like structure. Data, organized as branches and sub-branches, is depicted with the help of rectangles. With Treemap charts, you can easily drill down huge data to an unlimited number of levels.
Refer to the following code to add Treemap chart:
C# |
Copy Code |
---|---|
public void TreemapChart() { // Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.Worksheets[0]; // Prepare data for chart worksheet.Range["A1:D16"].Value = new object[,] { {"Region", "Subregion", "Country", "Population"}, {"Asia", "Southern", "India", 1354051854}, {null, null, "Pakistan", 200813818}, {null,null , "Bangladesh", 166368149}, {null,null , "Others", 170220300}, {null, "Eastern", "China", 1415045928}, {null, null, "Japan", 127185332}, {null,null , "Others", 111652273}, {null, "South-Eastern", null, 655636576}, {null, "Western", null, 272298399}, {null, "Central", null, 71860465}, {"Africa", "Eastern",null , 433643132}, {null, "Western",null , 381980688}, {null, "Northern", null, 237784677}, {null, "Others",null , 234512021}, {"Europe", null, null, 742648010}, {"Others",null ,null , 1057117703} }; worksheet.Range["A:D"].Columns.AutoFit(); // Add Treemap Chart IShape treeMapChartShape = worksheet.Shapes.AddChart(ChartType.Treemap, 250, 20, 360, 330); // Adding series to SeriesCollection treeMapChartShape.Chart.SeriesCollection.Add(worksheet.Range["A1:D16"], RowCol.Columns, true, true); // Configure Chart Title treeMapChartShape.Chart.ChartTitle.Text = "World Population"; // Saving workbook to Xlsx workbook.Save(@"33-TreemapChart.xlsx", SaveFileFormat.Xlsx); } |