comparing Date Time datum [vega-lite]

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! :joy:

I guess you need to quote the date as in datum['dateAnnounced']<'2020-03-15' (it’s a string)

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. :blue_heart:

1 Like

Glad to know you found the right forum. You’ll get better answers :slight_smile:

1 Like