在简单的Vega数据表中订购字段(日期)

时间:2019-02-12 03:22:26

标签: kibana vega vega-lite

我有一个简单的文本vega ata表,我们可以在Kibana中使用它,它可以正常工作,但是我试图找到一种根据到达日期对结果进行排序的方法,如下代码:

   {

  $schema: https://vega.github.io/schema/vega/v3.json
  config: {
    title: {offset: 20, fontSize: 14, font: "Helvetica", anchor:"start"}
  }
  title: {
    text: Departure Airport    Arrival Time   
  }
  background: white
  width: 1200
  height: 100
  padding: {"left": 0, "top": 5, "right": 5, "bottom": 5}
  autosize: {type: "pad"}

  // Define the data source
    data: [
    {
      name: source
      url: {
        // change "index" to the name of the index
        index: myindex*
        "%context%": true 
        body: {
          size: "10"
        }
      }
      format: {property: "hits.hits"}
      transform: [
        {
          type: flatten
          // change fields to the actual path for flight segment but keep _source as a prefix
          fields: ["_source.Something.FlightSegment"] 
          as: ["val"]
        }
        {
          type: formula
          as: x_position
          expr: width * 1 / 4
        }
        {type: "formula", as: "line_height", expr: "20"}
        {
          type: stack
          groupby: ["x_position"]
          field: line_height
          as: ["y0", "y1"]
        }
      ]
    }
  ]
  marks: [
    {
      type: text
      from: {data: "source"}
      interactive: true
      encode: {
        enter: {
          x: {field: "x_position", offset: -250}
          y: {field: "y0"}
          y2: {field: "y1"}
          align: {value: "right"}
          text: {field: "val.DepartureAirportCode"}
          font: {value: "Helvetica"}
          fontSize: {value: 14}
        }
      }
    }
    {
      type: text
      from: {data: "source"}
      interactive: true
      encode: {
        enter: {
          x: {field: "x_position", offset: -150}
          y: {field: "y0"}
          y2: {field: "y1"}
          align: {value: "left"}
          text: {field: "val.ArrivalDateTime"}
          font: {value: "Helvetica"}
          fontSize: {value: 14}
        }
      }
    }

  ]
}

这是这里的结果:

enter image description here

您可以看到结果已返回,但顺序不正确。我想做的是按ArrivalDateTime排序。

我的问题是,我看过的大多数教程都是针对实际图形的,而不仅仅是纯文本。

非常感谢有人在这里帮助我。

1 个答案:

答案 0 :(得分:0)

我对此也很好奇,所以发现Vega lite sort

尤其是sort by encoding from another field将完成这项工作。