powerbi - 将 Vega (Deneb) 仪表转换为在 PowerBI 中工作

标签 powerbi dax vega-lite vega deneb

代码:Link

对我来说,“83%”的值似乎是硬编码的,我希望根据 Power BI 测量值进行调整。我觉得我真的错过了一些东西,但是有没有办法导入 JSON,调整代码,然后拥有动态视觉效果?

在这个屏幕截图中,我尝试解释我的意思: deneb visual example

我尝试删除“信号”部分并将数据绑定(bind)到数据集,但无法使其工作。

感谢您的任何提示:)

更新: 截图os未格式化的增值: enter image description here

最佳答案

这是我的代码😀。您可以在此处查看其他示例:https://github.com/PBI-David/Deneb-Showcase

要使其在 Deneb 中发挥作用,请创建一个名为 myMeasure 的度量并将其放入 Deneb 中的字段中。然后添加以下代码。

 {
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 400,
  "height": 400,
  "padding": 50,
  "background": "#222431",
  "signals": [
    {
      "name": "textGradient",
      "update": "{gradient: 'linear', stops: [{offset: 0, color: '#14d8cc'}, {offset: 1, color: '#4c8bee'}]}"
    },
    {
      "name": "percent",
      "update": "0",
      "on": [
        {
          "events": {
            "type": "timer",
            "throttle": 0
          },
          "update": "round(data('dataset')[0]['myMeasure'])"
        }
      ]
    }
  ],
  "data": [
    {"name": "dataset"},
    {
      "name": "back",
      "values": [],
      "transform": [
        {
          "type": "sequence",
          "start": 0,
          "stop": 100,
          "step": 1,
          "as": "val"
        },
        {
          "type": "formula",
          "expr": "1",
          "as": "t"
        },
        {
          "type": "pie",
          "field": "t",
          "startAngle": {"signal": "0"},
          "endAngle": {"signal": "2*PI"}
        }
      ]
    },
    {
      "name": "front",
      "values": [],
      "transform": [
        {
          "type": "sequence",
          "start": 0,
          "stop": {"signal": "percent"},
          "step": 1,
          "as": "val"
        },
        {
          "type": "formula",
          "expr": "1",
          "as": "t"
        },
        {
          "type": "pie",
          "field": "t",
          "startAngle": {"signal": "0"},
          "endAngle": {
            "signal": "((2*PI)/100)*percent"
          }
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "color",
      "type": "linear",
      "domain": {
        "data": "back",
        "field": "val"
      },
      "range": [
        "#14d8cc",
        "#4c8bee",
        "#6567ee",
        "#b533d2",
        "#b533d2"
      ]
    }
  ],
  "marks": [
    {
      "type": "arc",
      "from": {"data": "back"},
      "encode": {
        "enter": {
          "fill": {"value": "#3f424e"},
          "x": {"signal": "width / 2"},
          "y": {"signal": "height / 2"}
        },
        "update": {
          "startAngle": {
            "field": "startAngle"
          },
          "endAngle": {
            "field": "endAngle"
          },
          "padAngle": {
            "signal": "0.015"
          },
          "innerRadius": {
            "signal": "(width / 2)-15"
          },
          "outerRadius": {
            "signal": "width / 2"
          }
        }
      }
    },
    {
      "type": "arc",
      "from": {"data": "front"},
      "encode": {
        "enter": {
          "fill": {
            "scale": "color",
            "field": "val"
          },
          "x": {"signal": "width / 2"},
          "y": {"signal": "height / 2"}
        },
        "update": {
          "startAngle": {
            "field": "startAngle"
          },
          "endAngle": {
            "field": "endAngle"
          },
          "padAngle": {
            "signal": "0.015"
          },
          "innerRadius": {
            "signal": "(width / 2)-15"
          },
          "outerRadius": {
            "signal": "width / 2"
          }
        }
      }
    },
    {
      "type": "arc",
      "data": [{"a": 1}],
      "encode": {
        "enter": {
          "fill": {"value": "#3f424e"},
          "x": {"signal": "width / 2"},
          "y": {"signal": "height / 2"}
        },
        "update": {
          "startAngle": {"signal": "0"},
          "endAngle": {
            "signal": "2*PI"
          },
          "innerRadius": {
            "signal": "(width / 2)-25"
          },
          "outerRadius": {
            "signal": "(width / 2)-20"
          }
        }
      }
    },
    {
      "type": "text",
      "data": [{}],
      "encode": {
        "update": {
          "text": {
            "signal": "percent + '%'"
          },
          "align": {"value": "center"},
          "fontWeight": {
            "value": "bold"
          },
          "fill": {
            "signal": "textGradient"
          },
          "x": {"signal": "width /2"},
          "y": {"signal": "width /2"},
          "dy": {"value": 10},
          "fontSize": {"value": 70}
        }
      }
    },
    {
      "type": "text",
      "data": [{}],
      "encode": {
        "update": {
          "text": {
            "value": "on target"
          },
          "align": {"value": "center"},
          "fontWeight": {
            "value": "bold"
          },
          "fill": {"value": "#9092a1"},
          "x": {"signal": "width /2"},
          "y": {"signal": "width /2"},
          "dy": {"value": 40},
          "fontSize": {"value": 30}
        }
      }
    }
  ]
}

关于powerbi - 将 Vega (Deneb) 仪表转换为在 PowerBI 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75881301/

相关文章:

excel - 有没有办法将 Power BI 表导出到 excel 中?

excel - 在 DAX 中使用多个过滤器

vega-lite - 如何在 vega-lite 折线图中画一条线?

plot - Vega-Lite:是否可以绘制一个 3 层图,其中一个 Y 轴仅由 2 个特定层使用?

javascript - 如何使用垂直或水平运算符在 Vega 中连接多个 View ?

powerbi - Power BI - 趋势颜色变化的折线图

asp.net-mvc - 如何在不使用 Azure 服务的情况下使用 Power Bi Microsoft

excel - 在 PowerQuery/M 中插入带有值列表的新列

powerbi - Power BI::如何比较 2 个不同时间轴上的 2 列?

t-sql - Power BI 字段参数过滤