You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power BI中创建双层环形图:需自定义视觉或Deneb(VegaLite)方案

实现Power BI双层环形图(自定义视觉/Deneb方案)

给定数据集

YearCategoryvalue
2021Category 125
2021Category 250
2021Category 325
2022Category 150
2022Category 225
2022Category 325

预期效果:双层同心环形图,内外层分别对应2021、2022两个年份,每个环形按类别划分扇区,展示对应数值的占比情况。


方案一:使用Power BI自定义视觉实现

  1. 打开Power BI Desktop,点击「主页」选项卡的「获取视觉对象」→「从AppSource获取」。
  2. 搜索并添加支持双层环形图的自定义视觉(例如Donut Chart Dual类工具)。
  3. 导入你的数据集到Power BI,确认Year、Category、value字段已正常加载。
  4. 将自定义视觉添加到报表画布后,配置字段:
    • 把Year拖到环形分组字段(不同视觉工具的字段命名可能不同,比如「Ring Group」);
    • 把Category拖到类别字段;
    • 把value拖到值字段。
  5. 根据需求调整样式:设置环形厚度、类别配色、数据标签显示等。

方案二:使用Deneb(Vega-Lite)实现

1. 数据准备

确保数据集已导入Power BI,字段结构与给定表格一致。

2. Deneb视觉配置

添加Deneb视觉到报表画布后,点击「编辑」进入Vega-Lite编辑器,替换为以下代码:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "双层环形图展示不同年份各类别数值占比",
  "data": {"name": "dataset"},
  "transform": [
    {
      "aggregate": [{"op": "sum", "field": "value", "as": "total_value"}],
      "groupby": ["Year", "Category"]
    },
    {
      "window": [{"op": "sum", "field": "total_value", "as": "year_total"}],
      "groupby": ["Year"]
    },
    {
      "calculate": "datum.total_value / datum.year_total",
      "as": "percentage"
    }
  ],
  "layer": [
    {
      "mark": {"type": "arc", "innerRadius": 60, "outerRadius": 100},
      "encoding": {
        "theta": {"field": "percentage", "type": "quantitative", "stack": true},
        "color": {"field": "Category", "type": "nominal", "legend": {"title": "类别"}},
        "opacity": {"condition": {"param": "hover", "value": 1}, "value": 0.7},
        "tooltip": [
          {"field": "Year", "title": "年份"},
          {"field": "Category", "title": "类别"},
          {"field": "total_value", "title": "数值"},
          {"field": "percentage", "title": "占比", "format": ".0%"}
        ]
      },
      "params": [{"name": "hover", "select": {"type": "point", "on": "mouseover"}}],
      "transform": [{"filter": "datum.Year == '2021'"}]
    },
    {
      "mark": {"type": "arc", "innerRadius": 20, "outerRadius": 50},
      "encoding": {
        "theta": {"field": "percentage", "type": "quantitative", "stack": true},
        "color": {"field": "Category", "type": "nominal"},
        "opacity": {"condition": {"param": "hover", "value": 1}, "value": 0.7},
        "tooltip": [
          {"field": "Year", "title": "年份"},
          {"field": "Category", "title": "类别"},
          {"field": "total_value", "title": "数值"},
          {"field": "percentage", "title": "占比", "format": ".0%"}
        ]
      },
      "transform": [{"filter": "datum.Year == '2022'"}]
    }
  ],
  "config": {
    "arc": {"stroke": "white", "strokeWidth": 2},
    "legend": {"orient": "bottom"}
  }
}

3. 字段绑定

在Deneb视觉的字段面板中,将:

  • Year字段拖入「Dataset」区域;
  • Category字段拖入「Dataset」区域;
  • value字段拖入「Dataset」区域。

保存配置后,即可生成符合预期的双层环形图。


内容的提问来源于stack exchange,提问作者Uday G Raikar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 19:16:28