如何创建树状图表

可能的使用场景

树状图表提供了数据的分级视图,可轻松找出模式,比如哪些项目是商店的畅销品。树的分支由矩形代表,每个子分支显示为较小的矩形。树状图表通过颜色和临近性显示类别,并且可以轻松显示大量数据,这在其他图表类型中可能会很困难。

todo:image_alt_text

树状图表

运行下面的代码后,您将会看到如下所示的树状图表。

todo:image_alt_text

示例代码

以下示例代码加载 样本 Excel 文件 并生成 输出 Excel 文件

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import FillType
# Create an instance of Workbook
workbook = Workbook("treemap.xlsx")
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Add a Treemap chart
pieIdx = worksheet.charts.add(ChartType.TREEMAP, 5, 6, 20, 12)
# Retrieve the Chart object
chart = worksheet.charts[pieIdx]
# Set the legend can be showed
chart.show_legend = True
# Set the chart title name
chart.title.text = "TreeMap Chart"
# Add series data range(D2:D13,actually)
chart.n_series.add("D2:F13", True)
# Set category data(A2:A13 is incorrect )
chart.n_series.category_data = "A2:C13"
# Show the DataLabels with category names
chart.n_series[0].data_labels.show_category_name = True
# Fill the PlotArea area with nothing
chart.plot_area.area.fill_format.fill_type = FillType.NONE
# Save the Excel file
workbook.save("out.xlsx")