Skip to main content

Hi all,


I would like to filter my records inside the vega-lite app to be independent from various views. Therefore I’m looking for a way to filter strings:



  1. record: “ABCD”

  2. record: “ABKF”

  3. record: “APFK”


I want to visualise only records where the string starts with “AB”. As far as I read the documentation, it is possible to filter numbers and complete strings. But is it possible to truncate strings? Or maybe there is another workaround? I expect to use it inside the transform statement.



Blockquote{

“$schema”: “https://vega.github.io/schema/vega-lite/v4.json”,

“transform”:

“filter”:{truncate(“field”:“PL reference”, 4)}, //something here is fishy…

“equal”:“AB”

],

“title”: “Shipment”,

“width”: “container”,

“height”: “container”,

“mark”: “bar”,

“encoding”: {

“x”: {

“type”: “nominal”,

“aggregate”:“count”

},

“y”:{

“type”: “quantitative”,

“field”: “PL reference”,

“aggregate”:“count”

}

}

}


Solution from StackOverflow, FYI:


"transform": [{"filter": "slice(datum.key, 0, 2) == 'AB'"}]

Reply