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

PowerBI Deneb饼图问题:额外弧段未堆叠、均从0点起始

饼图弧段堆叠问题修复方案

问题分析

你要实现带细分弧段的饼图,但当前两个弧段均从0度起始,未形成衔接堆叠——10%的“open %”显示正常,但“fulfilled”弧段没有接在它之后,而是从头开始绘制。

解决步骤

核心思路是让第二个弧段的起始角度等于第一个弧段的结束角度,具体实现分两种场景:

  • 固定占比场景:直接给第二个弧段的theta(起始角度)设置为第一个弧段的占比值,theta2设置为第一个占比加上自身占比值(基于总占比100的刻度)
  • 动态数据场景:通过transform计算第一个弧段的结束角度,传递给第二个弧段作为起始值

示例代码(固定占比)

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [
    // 外层open %弧段
    {
      "mark": {"type": "arc", "radius": 120, "radius2": 80},
      "encoding": {
        "theta": {"field": "value", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "color": {"value": "#e0e0e0"}
      },
      "data": {"values": [{"value": 10}]}
    },
    // 内层fulfilled弧段,起始角度衔接外层结束位置
    {
      "mark": {"type": "arc", "radius": 80, "radius2": 0},
      "encoding": {
        "theta": {"field": "start", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "theta2": {"field": "end", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "color": {"value": "#4caf50"}
      },
      "data": {"values": [{"start": 10, "end": 60}]} // 假设fulfilled占50%,10+50=60
    }
  ]
}

动态数据适配

如果数据是动态的,可以通过calculate变换自动计算起始角度:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"values": [{"open": 10, "fulfilled": 50}]},
  "transform": [
    {"calculate": "datum.open", "as": "fulfilled_start"},
    {"calculate": "datum.open + datum.fulfilled", "as": "fulfilled_end"}
  ],
  "layer": [
    {
      "mark": {"type": "arc", "radius": 120, "radius2": 80},
      "encoding": {
        "theta": {"field": "open", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "color": {"value": "#e0e0e0"}
      }
    },
    {
      "mark": {"type": "arc", "radius": 80, "radius2": 0},
      "encoding": {
        "theta": {"field": "fulfilled_start", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "theta2": {"field": "fulfilled_end", "type": "quantitative", "scale": {"domain": [0, 100]}},
        "color": {"value": "#4caf50"}
      }
    }
  ]
}

关键说明

  • 确保两个弧段的theta刻度都基于[0,100]的总占比,保证角度计算一致
  • 通过radius和radius2区分内外弧段的层级,避免视觉重叠
  • 动态场景下的transform计算可以自动适配数据变化,无需手动调整起始值

内容的提问来源于stack exchange,提问作者Lalu Prasad Thota

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 02:19:52