Skip to content

How to encode a field using conditions in Vega-Lite #8673

Answered by chanwutk
nickjwheatley asked this question in Q&A
Discussion options

You must be logged in to vote

For your dy question, would you mind checking this example?

For the other question, would you mind trying to transform with calculate before encoding?

Here is an example

  "mark": {
    "type":"text",
    "dy": {"expr": "datum.longer_bar_value < 0 ? 10 : -10"}
  },
  "transform": {
    {
      "calculate": "Math.abs(datum.thin_bar_value) > Math.abs(datum.thick_bar_value) ? datum.thin_bar_value : datum.thick_bar_value",
      "as": "longer_bar_value"
    }
  }
  "encoding": {
    "text": {
      "field": "longer_bar_value"
    },
    "y": {
      "field": "longer_bar_value",
      "type": "quantitative"
    }....
  }

Please let us know if you have any question :)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nickjwheatley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants