0


在 kibana 中,在 Vega-lite 可视化中,我想随时间创建应用程序 (AAAA) 的转换状态图。(时间线)
状态具有固定值(初始化、开始、运行...)

在 x 轴上是时间戳,
在 Y 上是状态级别,
一个矩形或条形来跟踪状态级别。

|====
| ======
| ============
______________________________
t0 t1 t2 ....

我的数据来自 ElasticSearch 中的查询并具有以下格式。

timestamp  app  state
  t0    AAAA  Init
  t1    AAAA  start
  t2    AAAA  Running
  t3    AAAA  stopped

在 vega 中,我想用条形或矩形表示状态,例如:Init 状态将由从 t0 开始到 t1 结束的矩形表示。但我没有这个信息!t1 在下一条数据线

是否可以通过利用下一行来计算此值。数据会是这样。

timestamp  app  state    ends 
  t0    AAAA  Init         t1
  t1    AAAA  start        t2 
  t2    AAAA  Running      t3
  t3    AAAA  stopped      t4 


欢迎任何帮助。

4

1 回答 1

0

您可以使用该操作通过窗口变换来执行此lead操作以查找下一个值。例如:

{
  "data": {
    "values": [
      {"timestamp": 0, "app": "A", "state": "init"},
      {"timestamp": 10, "app": "A", "state": "start"},
      {"timestamp": 25, "app": "A", "state": "run"},
      {"timestamp": 30, "app": "A", "state": "stop"},
      {"timestamp": 40, "app": "B", "state": "init"},
      {"timestamp": 55, "app": "B", "state": "start"},
      {"timestamp": 75, "app": "B", "state": "run"},
      {"timestamp": 85, "app": "B", "state": "stop"},
      {"timestamp": 90, "app": null, "state": "init"}
    ]
  },
  "transform": [
    {"window": [{"op": "lead", "field": "timestamp", "as": "t_stop"}]},
    {"filter": "datum.app != null"}
  ],
  "encoding": {
    "color": {"type": "nominal", "field": "app"},
    "x": {"type": "quantitative", "field": "timestamp"},
    "x2": {"type": "quantitative", "field": "t_stop"},
    "y": {
      "type": "nominal",
      "field": "state",
      "sort": {"op": "sum", "field": "timestamp", "order": "ascending"}
    }
  },
  "mark": "bar",
  "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json"
}

在此处输入图像描述

于 2018-08-01T18:32:35.117 回答