简体   繁体   English

Vega-lite 项目:风险矩阵

[英]Vega-lite project: Risk matrix

I am quite a newbie when it comes to vega and would appreciate any help.说到维加,我是个新手,非常感谢任何帮助。 I am currently creating a risk matrix with the two dimensions "damage potential" and "risk exposure".我目前正在创建一个风险矩阵,其中包含“潜在损害”和“风险暴露”两个维度。 The ultimate goal is to use in within PowerBI.最终目标是在PowerBI内使用。

My current status can be seen here: https://vega.github.io/editor/#/gist/d534904674d14f005e7cb08811dc8b62/spec.json我的当前状态可以在这里看到: https://vega.github.io/editor/#/gist/d534904674d14f005e7cb08811dc8b62/spec.json

Now I face two main challenges:现在我面临两个主要挑战:

  • How is it possible to color the fields so that the matrix looks like this: risk matrix picture如何为字段着色以使矩阵看起来像这样:风险矩阵图片
  • How can I populate the fields where there is no number so far (in this case: Damage: medium; Exposure: medium) with a 0?我如何用 0 填充到目前为止没有数字的字段(在本例中:损坏:中;曝光:中)?

Any help is welcome.欢迎任何帮助。 :) :)

Here you go.给你 go。

Editor. 编辑。

在此处输入图像描述

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://gist.githubusercontent.com/Hatico90/ec1d58ef5fe5d91cf6438e66fcd40bf0/raw/c5737c70fd45807a8435f2a97fe17fbc03bddf2b/riskmatrix",
    "format": {"type": "json"}
  },
  "width": 500,
  "height": 500,
  "transform": [
    {
      "pivot": "Exposure",
      "groupby": ["Damage"],
      "value": "Index",
      "op": "count"
    },
    {"fold": ["high", "low", "medium"]}
  ],
  "encoding": {
    "y": {
      "field": "key",
      "type": "ordinal",
      "scale": {"domain": ["high", "medium", "low"]}
    },
    "x": {
      "field": "Damage",
      "type": "ordinal",
      "scale": {"domain": ["low", "medium", "high"]}
    }
  },
  "layer": [
    {
      "mark": "rect",
      "data": {
        "values": [
          {"x": "low", "y": "low", "t": "green"},
          {"x": "low", "y": "medium", "t": "green"},
          {"x": "low", "y": "high", "t": "yellow"},
          {"x": "medium", "y": "low", "t": "green"},
          {"x": "medium", "y": "medium", "t": "yellow"},
          {"x": "medium", "y": "high", "t": "red"},
          {"x": "high", "y": "low", "t": "yellow"},
          {"x": "high", "y": "medium", "t": "red"},
          {"x": "high", "y": "high", "t": "red"}
        ]
      },
      "encoding": {
        "color": {
          "type": "nominal",
          "field": "t",
          "scale": {"range": {"field": "t"}},
          "legend": null
        },
        "y": {
          "field": "y",
          "type": "ordinal",
          "scale": {"domain": ["high", "medium", "low"]}
        },
        "x": {
          "field": "x",
          "type": "ordinal",
          "scale": {"domain": ["low", "medium", "high"]}
        }
      }
    },
    {
      "mark": {"type": "text"},
      "encoding": {"text": {"field": "value", "type": "quantitative"}}
    }
  ],
  "config": {"axis": {"grid": true, "tickBand": "extent"}}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM