简体   繁体   中英

Vega-Lite: Can I merge data sources?

I have time series data in the format:

    "data": {"values":[
    {"time":nnn,"Pressure":1},
    {"time":nnn,"Pressure":2},
    {"time":nnn,"Pressure":3}
    ] }

and another as:

        "data": {"values":[
        {"time":nnn,"Flow":1},
        {"time":nnn,"Flow":2},
        {"time":nnn,"Flow":3}
        ] }

If the time stamp is the same how can I merge it in to one array as this:

        "data": {"values":[

        {"time":nnn,"Pressure":1,"Flow":1},
        {"time":nnn,"Pressure":2,"Flow":2},
        {"time":nnn,"Pressure":3,"Flow":3}

        ] },

You can join datasets using a Lookup Transform . Here is a quick example using data similar to what you mentioned in the question ( view in vega editor ):

{
  "datasets": {
    "data1": [
      {"time": 0, "Pressure": 1},
      {"time": 1, "Pressure": 2},
      {"time": 2, "Pressure": 3}
    ],
    "data2": [
      {"time": 0, "Flow": 1},
      {"time": 1, "Flow": 2},
      {"time": 2, "Flow": 3}
    ]
  },
  "data": {"name": "data1"},
  "transform": [
    {
      "lookup": "time",
      "from": {"data": {"name": "data2"}, "key": "time", "fields": ["Flow"]}
    }
  ],
  "mark": "line",
  "encoding": {
    "x": {"field": "Pressure", "type": "quantitative"},
    "y": {"field": "Flow", "type": "quantitative"}
  }
}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM