简体   繁体   中英

How to filter data in vega-lite?

I have a following code for line plot, I am not sure how to use the filter transform, I have the mark and encoding inside a layer to use the tooltip for the plot

{
  "$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"}
        ]
      }
    }
  ]  
}

If I add

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

Its not working, may I how to filter the Value Field

It appears that you don't have a field named Value ; you have a field named _source.Value . So the correct way to filter would be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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