question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash after adding sort to encoding (cannot destructure property 'aggregate' of 'n' as it is undefined)

See original GitHub issue

Adding the sort: "-x" causes the chart to crash, removing it fixes it.

Notably, using sort: {field} seems to work.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "width": "container",
  "data": {
    "values": [
      {
        "label": "Food",
        "amount": 1200,
        "percent": 0.2901353965,
        "color": "red"
      },
      {
        "label": "Drink",
        "amount": 230,
        "percent": 0.05560928433,
        "color": "green"
      },
      {
        "label": "Accomodation",
        "amount": 1500,
        "percent": 0.3626692456,
        "color": "blue"
      },
      {
        "label": "Flight",
        "amount": 240,
        "percent": 0.0580270793,
        "color": "red"
      },
      {
        "label": "Entertainment",
        "amount": 542,
        "percent": 0.1310444874,
        "color": "green"
      },
      {
        "label": "Trips",
        "amount": 334,
        "percent": 0.08075435203,
        "color": "blue"
      },
      {"label": "Misc", "amount": 90, "percent": 0.02176015474, "color": "teal"}
    ]
  },
  "title": "By category",
  "encoding": {
    "y": {
      "field": "label",

  "sort": "-x",
      "title": null,
      "axis": null
    }
  },
  "layer": [
    {
      "mark": {"type": "bar", "tooltip": true, "cursor": "pointer"},
      "encoding": {
        "x": {
          "field": "amount",
          "type": "quantitative",
          "title": null,
          "axis": {"domain": false, "grid": false}
        },
        "color": {"field": "label", "legend": null},
        "opacity": {
          "condition": {"param": "selected", "value": 1},
          "value": 0.3
        }
      },
      "params": [
        {
          "name": "selected2",
          "select": {"type": "point", "encodings": ["y"], "toggle": false}
        }
      ]
    },
    {
      "mark": {
        "type": "text",
        "align": "right",
        "x": -5,
        "cursor": "pointer",
        "tooltip": true
      },
      "encoding": {
        "text": {"field": "label"},
        "opacity": {
          "condition": {"param": "selected", "value": 1},
          "value": 0.3
        }
      },
      "params": [
        {
          "name": "selected",
          "select": {"type": "point", "encodings": ["y"], "toggle": false}
        }
      ]
    }
  ]
}

Open the Chart in the Vega Editor

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
domoritzcommented, Apr 28, 2021

That’s a separate issue but yes!

0reactions
mattijncommented, Apr 28, 2021

It does not crash, but neither does it sort by x…, remove the text layer to get the order what OP wants.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Cannot destructure property of as it is undefined' during map
I need to pass through all the properties of this object and send them to other React component. But, not all objetcs have...
Read more >
Cannot destructure Property of Undefined Error in JS
The "Cannot destructure property of undefined" error occurs when we try to destructure a property from a value that is equal to `undefined`....
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
SyntaxError: JSON.parse: bad parsing. The JavaScript exceptions thrown by JSON.parse() occur when string failed to be parsed as JSON.
Read more >
ChangeLog-2018-09-11 - Apple Open Source
Windows ports can't compile Reverted changeset: "Use a Variant ... Crashes when using computed properties with rest destructuring and object spread.
Read more >
Prevent Error with Default {} when Destructuring
Why does it throw an Error? This is because you can't destructure undefined and null values. const { age } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found