Power BI 中的树状图Treemaps in Power BI

备注

可以在 Power BI Desktop 和 Power BI 服务中创建并查看这些视觉对象。These visuals can be created and viewed in both Power BI Desktop and the Power BI service. 本文中的步骤和图示来自 Power BI Desktop。The steps and illustrations in this article are from Power BI Desktop.

树状图将分层数据显示为一组嵌套矩形。Treemaps display hierarchical data as a set of nested rectangles. 层次结构中的每个级别都由一个有色矩形(分支)表示,其中包含更小的矩形(叶)。Each level of the hierarchy is represented by a colored rectangle (branch) containing smaller rectangles (leaves). Power BI 根据度量值来确定每个矩形内的空间大小。Power BI bases the size of the space inside each rectangle on the measured value. 矩形按大小从左上方(最大)到右下方(最小)排列。The rectangles are arranged in size from top left (largest) to bottom right (smallest).

“产品数(按类别和制造商)”树状图的屏幕截图。

例如,若要分析销售情况,可能有服装类别作为顶级分支:城市 、乡村 、青年 和混合 。For example, if you're analyzing your sales, you might have top-level branches for the clothing categories: Urban, Rural, Youth, and Mix. Power BI 会将类别矩形拆分为叶(即服装类别内的服装制造商)。Power BI would split your category rectangles into leaves, for the clothing manufacturers within that category. 这些叶根据销售量确定大小和底纹。These leaves would be sized and shaded based on the number sold.

在上面的“城市” 分支中,销售了许多“VanArsdel” 服装。In the Urban branch above, lots of VanArsdel clothing was sold. 销售的“Natura” 和“Fama” 服装较少。Less Natura and Fama was sold. “Leo” 服装仅销售了几件。Only a few Leo were sold. 因此,在树状图的“城市” 分支中:So, the Urban branch of your Treemap has:

  • “VanArsdel” 的矩形最大,位于左上角。The largest rectangle for VanArsdel in the top-left corner.

  • “Natura” 和“Fama” 的矩形略小。Slightly smaller rectangles for Natura and Fama.

  • 有其他许多矩形,代表已销售的其他所有服装。Lots of other rectangles for all the other clothing sold.

  • “Leo” 的矩形很小。A tiny rectangle for Leo.

通过比较每个叶节点的大小和底纹,可以跨其他服装类别比较销量:矩形越大,颜色越深,值就越大。You could compare the number of items sold across the other clothing categories by comparing the size and shading of each leaf node; larger and darker rectangles mean higher value.

想要先观看别人创建一个树状图?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.

备注

此视频使用较旧版本的 Power BI Desktop。This video uses an older version of Power BI Desktop.

何时使用树状图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.

先决条件Prerequisite

本教程使用零售分析示例 PBIX 文件This tutorial uses the Retail Analysis sample PBIX file.

  1. 在菜单栏的左上方,选择“文件” > “打开” From the upper left section of the menubar, select File > Open

  2. 查找零售分析示例 PBIX 文件的副本Find your copy of the Retail Analysis sample PBIX file

  3. 在报表视图中打开零售分析示例 PBIX 文件 报表视图屏幕截图图标Open the Retail Analysis sample PBIX file in report view Screenshot of the report view icon..

  4. 选择Select 黄色选项卡的屏幕截图。 ,以添加新报表页。to add a new page.

获取“零售分析示例” 数据集后,可以开始操作了。After you get the Retail Analysis Sample dataset, you can get started.

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

你将创建报表,并添加基本树状图。You'll create a report and add a basic treemap.

  1. 在“字段” 窗格中,依次选择“销售额” > “去年销售额” 度量值。From the Fields pane, select the Sales > Last Year Sales measure.

    依次选择“销售额”>“去年销售额”和生成的视觉对象的屏幕截图。

  2. 选择“树状图”图标Select the treemap icon “树状图”图标的屏幕截图 ,以将图表转换为树状图。to convert the chart to a treemap.

    不含配置的树状图的屏幕截图。

  3. 选择“项目” > “类别”,这会将“类别”添加到“组”井中 。Select Item > Category which will add Category to the Group well.

    Power BI 将创建一个树状图,其中矩形的大小基于总销售额,颜色代表类别。Power BI creates a treemap where the size of the rectangles is based on 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 Men's category has the highest sales and the Hosiery category has the lowest.

    已配置的树状图的屏幕截图。

  4. 选择“商店” > “连锁店”,这会将“连锁店”添加到“详细信息”井中以完成树状图 。Select Store > Chain which will add 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.

  5. 将鼠标悬停在连锁店区域上方以显示类别中该部分的工具提示。Hover over a Chain area to reveal the tooltip for that portion of the Category.

    例如,将鼠标悬停在“090-家居” 矩形中的 Fashions Direct ,将显示家居类别 Fashions Direct 部分的工具提示。For example, hovering over Fashions Direct in the 090-Home rectangle reveals the tooltip for Fashion Direct's portion of the Home category.

    显示的“主页”工具提示的屏幕截图。

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

突出显示树状图中的一个类别详细信息,以交叉突出显示和交叉筛选报表页上的其他可视化效果。Highlighting a Category or Detail in a treemap cross-highlights and cross-filters the other visualizations on the report page. 若要跟着本教程一起操作,请向此报表页添加一些视觉对象,或将树状图复制到此报表的其他一个报表页中。To follow along, either add some visuals to this report page or copy the treemap to one of the other pages in this report. 下图中的树状图已复制到概述页。The below image the treemap was copied over to the Overview page.

  1. 在树状图中,选择“类别” 或“类别” 中的“连锁店” 。On the treemap, select either a Category or a Chain within a Category. 这会交叉突出显示报表页上的其他可视化效果。That will cross-highlight the other visualizations on the page. 例如,选择“050-Shoes”会显示去年的鞋子销售额为 $16,352,432,其中“Fashions Direct”贡献了 $2,174,185 的销售额 。Selecting 050-Shoes, for example, shows you that last year's sales for shoes was $16,352,432 with Fashions Direct accounting for $2,174,185 of those sales.

    展示交叉突出显示的“商店销售情况概览”报表的屏幕截图。

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

  3. 若要管理图表如何相互交叉突出显示和交叉筛选,请参阅更改 Power BI 报表中视觉对象的交互方式To manage how charts cross-highlight and cross-filter each other, see Change how visuals interact in a Power BI report.

后续步骤Next steps