如何在 vega-lite 中过滤数据?

How to filter data in vega-lite?

我有以下线图代码,我不确定如何使用过滤器变换,我在图层内有标记和编码以使用绘图工具提示

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.4.json",
  "title": "Dashboard",
  "data": {
    "url" : {
        "%context%": true,
        "index": "paytrans",
        "body": {
          "size":10000,
          "_source": ["Metrics","Value","ModelName"],
        }
      }  
      "format": {"property": "hits.hits"},
  }, 
  "layer": [
    {  
      "mark": {
        "type": "line",
        "point": true
      },
      "encoding": {
        "x": {"field": "_source.ModelName", 
              "type": "ordinal", 
              "title":"Models"
              "axis": {
                "labelAngle": 0
                }
              },
        "y": {"field": "_source.Value", "type": "quantitative", "title":"Metric Score"
          "scale": { "domain": [0.0, 1.0] }},
        "color": {"field": "_source.Metrics", "type": "nominal", "title":"Metrics"},
        "tooltip": [
          {"field": "_source.Metrics", "type": "nominal", "title":"Metric"},
          {"field": "_source.Value", "type": "quantitative", "title":"Value"}
        ]
      }
    }
  ]  
}

如果我加上

  "transform": [
   {
      "filter": "datum.Value <= 0.5"
    }
  ],

它不起作用,请问如何过滤值字段

您似乎没有名为 Value 的字段;您有一个名为 _source.Value 的字段。所以正确的过滤方式是:

  "transform": [
   {
      "filter": "datum._source.Value <= 0.5"
    }
  ],