如何创建树状图表
Contents
[
Hide
]
可能的使用场景
树状图表提供了数据的分级视图,可轻松找出模式,比如哪些项目是商店的畅销品。树的分支由矩形代表,每个子分支显示为较小的矩形。树状图表通过颜色和临近性显示类别,并且可以轻松显示大量数据,这在其他图表类型中可能会很困难。
树状图表
运行下面的代码后,您将会看到如下所示的树状图表。
示例代码
以下示例代码加载 样本 Excel 文件 并生成 输出 Excel 文件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Workbook | |
Workbook workbook = new Workbook("treemap.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add a Treemap chart | |
int pieIdx = worksheet.Charts.Add(ChartType.Treemap, 5, 6, 20, 12); | |
// Retrieve the Chart object | |
Chart chart = worksheet.Charts[pieIdx]; | |
// Set the legend can be showed | |
chart.ShowLegend = true; | |
// Set the chart title name | |
chart.Title.Text = "TreeMap Chart"; | |
// Add series data range(D2:D13,actually) | |
chart.NSeries.Add("D2:F13", true); | |
// Set category data(A2:A13 is incorrect ) | |
chart.NSeries.CategoryData = "A2:C13"; | |
// Show the DataLabels with category names | |
chart.NSeries[0].DataLabels.ShowCategoryName = true; | |
// Fill the PlotArea area with nothing | |
chart.PlotArea.Area.FillFormat.FillType = FillType.None; | |
// Save the Excel file | |
workbook.Save("out.xlsx");; |