Scatter Plot with multiple Y values for each X using VEGA

Hi I have a question visualizing multiple y values for each x in vega.
In case of simple x,y data like this (one data per one timestamp)

timestamp tag_value
2019-10-24 10:00:00 10.9
2019-10-24 10:0:01 11.0

I could easily draw the scatter plot using this vega script,

{
  $schema: https://vega.github.io/schema/vega-lite/v2.json
  data: {
    # URL object is a context-aware query to Elasticsearch
    url: {
      # The %-enclosed keys are handled by Kibana to modify the query
      # before it gets sent to Elasticsearch. Context is the search
      # filter as shown above the dashboard. Timefield uses the value 
      # of the time picker from the upper right corner.
      %context%: true
      %timefield%: @timestamp
      index: vega_test_data
      body: {
        size: 10000
        _source: ["@timestamp", "TAG_VALUE"]
      }
    }
    # We only need the content of hits.hits array
    format: {property: "hits.hits"}
  }
  transform: [
    {calculate: "toDate(datum._source['@timestamp'])", as: "time"}
  ]
  mark: point
  encoding: {
    x: {field: "time"
        type: "temporal"
        axis: {title: "Timestamp"}
        }
    y: {field: "_source.TAG_VALUE"
        type: "quantitative"
        axis : {title : "Tag Value"}
        }
  }
}

But, my y axis data has multiple values, so it is array type by each timestmap(x value)
For example,

timestamp tag_value
2019-10-24 10:00:00 [10.9, 11.0, 10.4 .....10.2]
2019-10-24 10:0:01 [10.7, 11.1, 10.5 .....12.2]

How can I draw multiple y values per x using vega?(The y values are array types per each x)

You need to flatten your data, e.g. convert

timestamp tag_value
2019-10-24 10:00:00 [10.9, 11.0, 10.4 .....10.2]
2019-10-24 10:0:01 [10.7, 11.1, 10.5 .....12.2]

to a flat table

timestamp tag_value
2019-10-24 10:00:00 10.9
2019-10-24 10:00:00 11.0
2019-10-24 10:00:00 10.4
... ...
2019-10-24 10:00:00 10.2
2019-10-24 10:0:01 10.7
2019-10-24 10:0:01 11.1
... ...

I saw that Vega-Lite has flatten transform, but I don't know which version added that, and if Kibana actually supports it. If it doesn't, you may have to switch to Vega and use flatten transform there (Kibana does support it).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.