Power BI 中的树状图(教程)Treemaps in Power BI (Tutorial)

树状图将分层数据显示为一组嵌套矩形。Treemaps display hierarchical data as a set of nested rectangles. 一个有色矩形(通常称为“分支”)代表层次结构中的一个级别,该矩形包含其他矩形(“叶”)。Each level of the hierarchy is represented by a colored rectangle (often called a "branch") containing other rectangles ("leaves"). 根据所测量的定量值分配每个矩形的内部空间,从左上方(最大)到右下方(最小)按大小排列矩形。The space inside each rectangle is allocated based on the quantitative value being measured, with the rectangles arranged in size from top left (largest) to bottom right (smallest).

例如,如果我正在分析销量,我可能会为服装类别设置顶层矩形(分支):城市乡村青年混合For example, if I'm analyzing my sales, I might have top-level rectangles (branches) for the clothing categories: Urban, Rural, Youth, and Mix. 我的类别矩形将包含代表服装厂商的较小的矩形(叶),这些较小的矩形将根据销量设置大小和明暗度。My category rectangles would contain smaller rectangles (leaves) for the clothing manufacturers within that category, and these smaller rectangles would be sized and shaded based on the number sold. 在上面提到的城市分支中,售出了大量 Maximus 服装,Natura 和 Fama 较少,Leo 则非常少。In the Urban branch above, lots of Maximus clothing was sold, less Natura and Fama, and very little Leo. 因此,我的树状图的城市分支将具有代表 Maximus 的最大矩形(位于左上角)、代表 Natura 和 Fama 的稍微小点的矩形、代表所有其他销售的服装的大量其他矩形以及代表 Leo 的一个很小的矩形。So, the Urban branch of my Treemap would have the largest rectangle for Maximus (in the top left corner), slightly-smaller rectangles for Natura and Fama, lots of other rectangles representing all the other clothing sold, and a tiny rectangle for Leo. 通过比较每个叶节点的大小和明暗度我可以比较其他服装类别销售的服装数量;矩形越大,颜色越深,则值越大。And I could compare the number of items sold across the other clothing categories by comparing the size and shading of each leaf node; the larger the rectangle and the darker the shading, the higher the value.

何时使用树状图When to use a treemap

当存在以下情况时,树状图是一个不错的选择:Treemaps are a great choice:

  • 要显示大量的分层数据。to display large amounts of hierarchical data.
  • 条形图不能有效地处理大量值。when a bar chart can't effectively handle the large number of values.
  • 要显示每个部分与整体之间的比例。to show the proportions between each part and the whole.
  • 要显示层次结构中指标在各个类别层次的分布的模式。to show the pattern of the distribution of the measure across each level of categories in the hierarchy.
  • 要使用大小和颜色编码显示属性。to show attributes using size and color coding.
  • 要发现模式、离群值、最重要因素和异常。to spot patterns, outliers, most-important contributors, and exceptions.


  • Power BI 服务或 Power BI DesktopPower BI service or Power BI Desktop
  • 零售分析示例Retail Analysis sample

创建一个基本的树状图Create a basic treemap

想要先观看别人创建一个树状图?Want to watch someone else create a treemap first? 跳到此视频的 2:10 处观看 Amanda 创建一个树状图。Skip to 2:10 in this video to watch Amanda create a treemap.

或者,创建你自己的树状图。Or, create your own treemap. 以下说明使用零售分析示例。These instructions use the Retail Analysis Sample. 若要跟着介绍一起操作,请登录 Power BI 服务(不是 Power BI Desktkop),并依次选择“获取数据”>“示例”“零售分析示例”>>“连接”“转至仪表板”>To follow along, sign in to Power BI service (not Desktkop) and select Get Data > Samples > Retail Analysis Sample > Connect > Go to dashboard. 在报表中创建可视化效果需要对数据集和报表拥有编辑权限。Creating visualizations in a report requires edit permissions to the dataset and report. 幸运的是,Power BI 示例是可以编辑的。Luckily, the Power BI samples are editable. 但如果有人与你共享报表,你将无法添加新的可视化效果。But if someone shares a report with you, you won't be able to add new visualizations.

  1. 选择“总商店数”磁贴,打开“零售分析示例”报表。Select the "Total stores" tile to open the Retail Analysis sample report.
  2. 打开编辑视图并选择“销售” > “上年度销售额”指标。Open Editing View and select the Sales > Last Years Sales measure.
  3. 将图表转换为树状图。Convert the chart to a treemap.
  4. 项目 > 类别拖放到中。Drag Item > Category to the Group well. Power BI 将创建一个树状图,其中矩形的大小反映总销售额,颜色代表类别。Power BI creates a treemap where the size of the rectangles reflects total sales and the color represents the category. 实际上你已创建以可视化方式描述按类别的总销售额的相对大小的层次结构。In essence you've created a hierarchy that visually describes the relative size of total sales by category. 男装类的销售额最高,类销售额最低。The Mens category has the highest sales and the Hosiery category has the lowest.
  5. 将“商店” > “连锁店”拖放到“详细信息”以完成树状图。Drag Store > Chain to the Details well to complete your treemap. 现在你可以按类别和连锁店比较上年度的销售额。You can now compare last year's sales by category and chain.


    不能同时使用色彩饱和度和详细信息。Color Saturation and Details cannot be used at the same time.

  6. 将鼠标悬停在连锁店区域上方以显示类别中该部分的工具提示。Hover over a Chain area to reveal the tooltip for that portion of the Category. 例如,将鼠标悬停在 040-Juniors 矩形中的 Lindseys 上方可显示青少年类别的 Lindsey 部分的工具提示。For example, hovering over Lindseys in the 040-Juniors rectangle reveals the tooltip for Lindsey's portion of the Juniors category.
  7. 将树状图添加为仪表板磁贴(固定视觉对象)Add the treemap as a dashboard tile (pin the visual).
  8. 保存报表Save the report.

突出显示和交叉筛选Highlighting and cross-filtering

有关使用筛选器窗格的信息,请参阅向报表添加筛选器For information about using the Filters pane, see Add a filter to a report.

突出显示树状图中的一个类别或详细信息可交叉突出显示和交叉筛选报表页上的其他可视化效果…,反之亦然。Highlighting a Category or Details in a treemap cross-highlights and cross-filters the other visualizations on the report page... and vice versa. 若要执行此操作,可将一些视觉对象添加到同一页,或者将树状图复制/粘贴到已有其他视觉对象的报表页面。To follow along, either add some visuals to the same page or copy/paste the treemap to a report page that already has other visuals.

  1. 在树状图中,选择一个类别或类别中的一个连锁店。On the treemap, select either a Category or a Chain within a Category. 这样可以交叉突出显示页面上的其他可视化效果。This cross-highlights the other visualizations on the page. 例如,选择 050-Shoes 可显示鞋子的上年度销售额为 $3,640,471,其中 $2,174,185 来自 Fashions Direct。Selecting 050-Shoes, for example, shows me that last year's sales for shoes was $3,640,471 with $2,174,185 of that coming from Fashions Direct.

  2. 在按连锁店的上年度销售额饼图中,选择“Fashions Direct”切片,交叉筛选树状图。In the Last Year Sales by Chain pie chart, selecting the Fashions Direct slice, cross-filters the treemap.

  3. 若要管理图表相互交叉突出显示和交叉筛选的方式,请参阅 Visualization interactions in a Power BI report(Power BI 报表中的可视化效果交互)To manage how charts cross-highlight and cross-filter each other, see Visualization interactions in a Power BI report

后续步骤Next steps

将可视化效果固定到仪表板 Pin a visualization to a dashboard
Power BI - 基本概念Power BI - Basic Concepts

更多问题?More questions? 尝试参与 Power BI 社区Try the Power BI Community