Forum Discussion

Salle's avatar
Salle
Advocate I
3 years ago
Solved

Deneb: Multi-layer card

Hi everyone, I am still learning the basics and exploring the world of Deneb vega-lite. 🙂 I am currently trying to figure out how to freely position text and DAX measures in a Deneb chart. Examp...
  • dm-p's avatar
    dm-p
    3 years ago

    Hi Salle,

    I assume that you want the text to display the mean value? If so, you need to add a text encoding channel property and put the field in there. So, your snippet of JSON that didn't match Vega-Lite's construct for what I think you want to do should look like this:

    "encoding": {
      "text": { "field": "Diameter Mean" },
      "x": {"value": 0},
      "y": {"value": 10}
    }

    My output now looks as follows:

    Revised spec:

    {
      "data": {"name": "dataset"},
      "title": "Information",
      "background": "lightblue",
      "height": 400,
      "width": 200,
      "layer": [
        {
          "mark": {
            "type": "text",
            "align": "left",
            "baseline": "top",
            "font": "sans-serif",
            "fontSize": 24,
            "dx": 10,
            "dy": 0,
            "xOffset": 0,
            "yOffset": 0
          },
          "encoding": {
            "text": {
              "field": "Diameter Mean"
            },
            "x": {"value": 0},
            "y": {"value": 10}
          }
        },
        {
          "mark": {
            "text": "Mean",
            "type": "text",
            "align": "left",
            "baseline": "top",
            "font": "sans-serif",
            "fontSize": 16,
            "dx": 10,
            "dy": 0,
            "xOffset": 0,
            "yOffset": 0
          },
          "encoding": {
            "x": {"value": 0},
            "y": {"value": 30}
          }
        },
        {
          "mark": {
            "text": "Diameter Median",
            "type": "text",
            "baseline": "top",
            "align": "left",
            "font": "sans-serif",
            "fontSize": 16,
            "dx": 10,
            "dy": 0,
            "xOffset": 0,
            "yOffset": 0
          },
          "encoding": {
            "x": {"value": 0},
            "y": {"value": 80}
          }
        },
        {
          "mark": {
            "text": "Diameter Max",
            "type": "text",
            "baseline": "top",
            "align": "left",
            "font": "sans-serif",
            "fontSize": 16,
            "dx": 10,
            "dy": 0,
            "xOffset": 0,
            "yOffset": 0
          },
          "encoding": {
            "x": {"value": 0},
            "y": {"value": 130}
          }
        }
      ]
    }

    Regards,

    Daniel