【问题标题】:Compare Date in Condition [Vega-Lite]比较日期 [Vega-Lite]
【发布时间】:2020-08-13 21:54:42
【问题描述】:

我对此非常陌生,并且是第一次尝试 Observable 和 Vega-Lite。以下代码在数据是定量字符串时有效,但在日期时无效。

vl.color({"condition":{"test":"datum['dateAnnounced']<'2020-03-15'","value":"black"}, "value":"red"})

有人可以告诉我比较日期字段的正确方法吗?提前致谢!

【问题讨论】:

    标签: datetime colors observable conditional-formatting vega-lite


    【解决方案1】:

    condition.test 接受 Predictate。它具有您正在使用的字符串格式,但也可以是这样的对象:

    condition: {
      test: {
        field: 'dateAnnounced', // your date field
        lt: { year: 2020, month: 3, date: 15 } // 'less than' a date in Vega DateTime format
      }
    }
    

    他们称这个对象为“字段谓词”。它具有field 属性和一个比较运算符ltgtequal 等。 有一些来自文档的Field Predicate section 的例子:

    {"field": "car_color", "equal": "red"} // car_color === red
    
    {"field": "height", "lt": 180} // height < 180
    
    {"field": "date", // 2006-01-01 < date && date < 2008-02-20
      "range": [
        {"year": 2006, "month": "jan", "date": 1},
        {"year": 2008, "month": "feb", "date": 20}
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 2020-03-19
      • 2020-07-05
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      • 2021-01-26
      • 2011-12-31
      • 2018-11-24
      相关资源
      最近更新 更多