VEGA data import

Hi!
I’m trying to import 2 attributes from a device, my goal is to plot ‘Torque’ x ‘Rotation’ of an electric motor.

My code works in the “VEGA Editor Online” but when I transfer to Losant I get “Invalid Vega-Lite v2 configuration”. Code:

{
  "width": {{block.width}},
  "height": {{block.height}},
  "autosize": {
    "type": "fit",
    "contains": "padding"
  },

  "data": [
    {
      "name": "torque"
    },

    {
    "name": "rotation"
    }
  
  ],
....

}

P.S .: “rotation” and “torque” refer to a time series query, which I plotted over time without any problems.

1 Like

Hi @Kaue_Delazzeri and welcome to the forums!

Two questions …

  • The Vega-Lite Online Editor does not use Vega-Lite v2; it actually uses the recently released Vega-Lite v4 by default. To that end, if you switch your Vega-Lite version in your dashboard block to Vega-Lite v3, does your block work?
  • If not, can you please paste the entire Vega configuration here if it does not have any sensitive information in it?

We still support Vega-Lite v2 in the dashboard block so as not to break any legacy users’ existing blocks; but if you are writing a new Custom Chart, I recommend using Vega-Lite v3 or Vega 5. We’ll be rolling out a change in the coming weeks to add Vega-Lite v4 support.

1 Like

To plot the relation between two variables as scatter plot you can use the “transform” function from Vega. Here it is an example code (replace data_01 and data_02 with the names you configured in the block):

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

This code works perfectly if the goal is to plot one variable against another.

But the problem is that I want to do a regression, so I can’t apply the ‘transform’ function to “import” my time series query. Or can I?

Hi @Dylan_Schuster and thank you!

My code works on vega-lite v2 and v3, but it doesn’t work on v4 and v5 on losant.

The main problem is whether it is possible to import two variables in the same VEGA ‘data’ function on the Losant platform.

The code it’s just like @Kelvin_Andrade1 posted.

Hi @Kaue_Delazzeri,

Just for clarification, what errors are you seeing with the Custom Chart Block? As well, what is your current configuration? Any screenshots you may have would be helpful as well! :smile:

Thanks,
Julia