Thanks to Fil for the conditional code snippet , I was able to do this successfully:
vl.color({"condition":{"test":"datum['age']<50","value":"black"}, "value":"red"}),
but when I tried to parse a Date Time datum:
vl.color({"condition":{"test":"datum['dateAnnounced']<2020-03-15","value":"black"}, "value":"red"}),
I got the following error:
Error: Expression parse error: datum[‘dateAnnounced’]<2020-03-15
I’m guessing it’s because I can’t compare Date Time with basic comparison operators? Can someone please advise otherwise?
P/S: dateAnnounced is in yyyy-mm-dd format
P/P/S: Had to wait 17 hours before I could post more questions!
Fil
April 29, 2020, 11:24am
2
I guess you need to quote the date as in datum['dateAnnounced']<'2020-03-15'
(it’s a string)
Fil
April 29, 2020, 11:27am
3
PS: It looks like your questions are all about vega-lite, remember this forum is for observable.
1 Like
Ah, is vega-lite not a part of Observable? Sorry, I had the wrong impression…I’ll look for a vega-lite forum for my future questions.
In any case, I’ve tried having it with and without quotes, single and double quotes but I get a different error each time…
vl.filter({‘datum’:[‘discharged’]} == 1),
TypeError: Cannot read property ‘length’ of undefined
Thanks for pointing out that I was asking in the wrong place! Sorry I was too eager and jumped straight in without finding out what Observable was and didn’t even know the difference between JSON and JS formatting! I’ve found a Google group for Vega and Vega-lite.
vl.filter(“datum.discharged == 1”),
This works but it doesn’t when I’m comparing temporal-type fields i.e. date.
vl.color({“condition”:{“test”:“datum[‘dateAnnounced’]<‘2020-03-15’”,“value”:“black”}, “value”:“red”}),
No error, it just doesn’t work.
Thanks again, @Fil .
1 Like
Fil
April 29, 2020, 2:30pm
6
Glad to know you found the right forum. You’ll get better answers
1 Like