Help

Filtering strings in Vega-Lite

Solved
Jump to Solution
1407 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Felix_Fabich
6 - Interface Innovator
6 - Interface Innovator

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”
}
}
}

1 Solution

Accepted Solutions
Felix_Fabich
6 - Interface Innovator
6 - Interface Innovator

Solution from StackOverflow, FYI:

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

See Solution in Thread

1 Reply 1
Felix_Fabich
6 - Interface Innovator
6 - Interface Innovator

Solution from StackOverflow, FYI:

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