1

我提前感谢您提供的任何线索。在下面的简短示例中,PMT2(来自“Pmt Type”字段)和 RX(来自“Measure”字段)的组合不是数据的一部分。所以我想消除这种组合出现在我的可视化中。但它仍然出现。什么规范会阻止它发生?"resolve": {"axis": {"y": "independent"}} 没有像我预期的那样工作。

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
      "values": [
{"Pmt Type":"PMT2","PRE POST":"PRE","Rx":0.8,"GP":52},
{"Pmt Type":"PMT2","PRE POST":"POST","GP":30},
{"Pmt Type":"PMT1","PRE POST":"PRE","GP":52},
{"Pmt Type":"PMT1","PRE POST":"POST","GP":36}
      ]
  },
  "transform": [
      {
          "aggregate" : [
              {"op":"sum","field":"Rx","as":"Rx"},
              {"op":"sum","field":"GP","as":"GP"}
          ],
          "groupby":["PRE POST","Pmt Type"]
      },
      {
        "comment":"This is to create the Measure dimension for nesting",    
        "fold": ["Rx","GP"], "as":["Measure","Value"]
      },
      {
        "comment":"This is to filter out the unwanted combinations",
        "filter":"datum['Pmt Type']=='PMT2' || datum['Measure']=='GP'"
      }
  ],
  "config": {
      "view": {
          "strokeWidth": 2,
          "width":{"step": 70}
      }
  },
  "mark": {"type":"text"},
  "encoding": {
        "row":{"field":["Pmt Type"]},
        "y": {
            "field": "Measure"
        },
        "x": {
            "field": "PRE POST"
        },
        "text": {"field":"Value"}   
  },
   "resolve": {"axis": {"y": "independent"}}
}
4

1 回答 1

0

我让它像这样工作:(1)使用 voncat 而不是“行”(2)在 voncat 的每个视图中过滤记录。结果是这样的:

{"$schema": "https://vega.github.io/schema/vega-lite/v5.json","data": {"values": [{"Pmt Type":"PMT2","PRE POST":"PRE","Measure":"Rx", "Value":0.8},{"Pmt Type":"PMT2","PRE POST":"PRE","Measure":"GP","Value":52},{"Pmt Type":"PMT1","PRE POST":"PRE","Measure":"GP", "Value":48}]},"config": {"view": {"strokeWidth": 2,"width":{"step": 70}}},"vconcat":[{ "transform":[{"filter":"datum['Pmt Type']=='PMT1'"}],"mark": {"type":"text"},"encoding": {"y": {"field": "Measure"},"x": {"field": "PRE POST"},"text": {"field":"Value"} }},{ "transform":[{"filter":"datum['Pmt Type']=='PMT2'"}],"mark": {"type":"text"},"encoding": {"y": {"field": "Measure"},"x": {"field": "PRE POST"},"text": {"field":"Value"}}}]}
于 2022-01-15T23:58:02.437 回答