Graphing one attribute as a function of another

I got my Vega lite scatter plot to work with data values manually entered in the Vega config.
When starting adding a data set with time series data, I realize I can only specify one attribute per data set. How can I merge time series data from 2 attributes so I can scatter plot one attribute in relation to the second attribute?

@Lars_Andersson,

Glad you were able to get your first issue worked out.

Can you send along a copy of the now current config you’re working on? As well as your current Data Query set up for the block?

Is your question how do I plot multiple (X,Y) scatter plots on the same chart? So from yesterday you are interested in plotting the time series data for both flow and pressure against a common time component, or do you want to have Pressure as your x-series data and Flow as your y-series data?

Thanks,
@Aidan_Zebertavage

Pressure as X, Flow as Y

@Lars_Andersson

Could you send along your current configuration now and Data Query set up for the block on your dashboard? These will help me get a better understanding of where you’re currently at.

Thanks
@Aidan_Zebertavage

All I have right now is the config below. When I started adding a data set I realized I can only pick one attribute, so I wasn’t sure which way to go. It looks like I can maybe merge data from 2 data sets, but I haven’t tried that yet.

{

“width”: {{block.width}},

“height”: {{block.height}},

“autosize”: {

“type”: “fit”,

“contains”: “padding”

},

“data”: {“values”:[

{“Pressure”:1,“Flow”:1},

{“Pressure”:2,“Flow”:2},

{“Pressure”:2.1,“Flow”:2.05},

{“Pressure”:3,“Flow”:3}

] },

“mark”: “point”,

“encoding”: {

“x”: {

"field": "Pressure", 

"type": "quantitative"

},

“y”: {

"field": "Flow", 

"type": "quantitative"

}

}

}

@Lars_Andersson,

We’ve been able to plot multiple data series on a single plot to work by using Vega layers, and that may point you in the right direction. We have an example in our docs on how to configure multiple time-series on a single plot.

You can see in the example that we’ve plotted both a time-series and a gauge series set of data on the same plot.

Thanks,
@Aidan_Zebertavage

But I don’t think I need layers, feels like the probvlem lays within the data structure.
I need both attributes in the same data source.

@Lars_Andersson,

I believe I see your issue now, the problem lies in the fact that defining the time series query only allows for association of a single attribute to that query. When in actuality what you want is at each time point, give me the pressure and flow as the x,y coordinates and plot that.

So I’ve dug into a bit into past Losant forum posts actually and I believe I’ve found a solution. You need to use the Vega-Lite Lookup Transform feature. Vega also provides quite a few scatter plot examples.

I was curious on how this might look in Losant and spun up a very basic example. I simulated a device for pressure and flow values, and then configured a custom chart block which you can see below. I’ve also attached what I’ve set my config to.

Please let me know if this helps steer you in the right direction. You’ll likely need to play around with the duration and resolution values in the query set up to get to exactly what you’re looking for.

Thanks,
@Aidan_Zebertavage

{ "width": {{block.width}},
"height": {{block.height}},
"autosize": {
"type": "fit",
"contains": "padding"
 },
"data": {
"name": "flow"
},
"transform": [
{
  "lookup": "time",
  "from": {
    "data": {
      "name": "pressure"
    },
    "key": "time",
    "fields": [
      "value"
    ]
  },
  "as": [
    "data_02_new_name"
  ]
}
],
"layer": [
   {
  "mark": "point",
  "encoding": {
    "x": {
      "field": "value",
      "title": "flow",
      "type": "quantitative"
    },
    "y": {
      "field": "data_02_new_name",
      "title": "pressure",
      "type": "quantitative"
    }
  }
  }
]
}