Search code examples
powerbivisualizationpowerbi-desktopvega-litedeneb

Change position/location of Axis Labels


I would like to change the position of the X-axis so that the labels appear at the top rather than the bottom (see image):

enter image description here

I have achieved this in the past but now I can't remember! 🤣

I have tried changing the label specs, for "position" but with no luck!

Any help is greatly appreciated

Edit: Perhaps the only alternative is the example below? enter image description here

Edit 2.0: I experimented with "Position": - and managed to get the Axis labels in the correct place, but I think this is an accident and incorrect syntax. I'm unable to change the offset here as well

enter image description here


Solution

  • Is this what you're after? If so, just add an orient and adjust the spacing.

    enter image description here

    {
      "data": {"name": "dataset"},
      "spacing": 5,
      "vconcat": [
        {
          "spacing": 5,
          "hconcat": [
            {
              
              "name": "MainMatrix",
              "mark": {
                "type": "rect",
                "tooltip": {
                  "content": "data"
                }
              },
              "encoding": {
                "x": {
                  "field": "DayNameShort",
                  "type": "nominal",
                  "sort": null,
                  "axis": {"title": null, "orient":"top"}
                },
                "y": {
                  "field": "MonthShort",
                  "axis": {"title": null},
                  "sort": null
                },
                "fill": {
                  "field": "Streams",
                  "type": "quantitative",
                  "legend": null
                },
                "opacity": {
                  "condition": {
                    "test": {
                      "field": "_selected_",
                      "equal": "off"
                    },
                    "value": 0.3
                  },
                  "value": 1
                }
              }
            },
            {
              "name": "RowBar",
              "width": 70,
              "mark": {
                "type": "bar",
                "height": {"band": 0.95},
                "tooltip": true,
                "color": "#1DB954"
              },
              "encoding": {
                "y": {
                  "field": "MonthShort",
                  "axis": null,
                  "sort": null
                },
                "x": {
                  "field": "Streams",
                  "type": "quantitative",
                  "aggregate": "sum",
                  "axis": {
                    "labels": false,
                    "title": null
                  }
                },
                "opacity": {
                  "condition": {
                    "test": {
                      "field": "_selected_",
                      "equal": "off"
                    },
                    "value": 0.3
                  },
                  "value": 1
                }
              }
            }
          ]
        },
        {
          "hconcat": [
            {
              "name": "ColBar",
              "height": 50,
              "mark": {
                "type": "bar",
                "width": {"band": 0.95},
                "tooltip": true,
                "color": "#1DB954"
              },
              "encoding": {
                "x": {
                  "field": "DayNameShort",
                  "sort": null,
                  "axis": null
                },
                "y": {
                  "field": "Streams",
                  "type": "quantitative",
                  "aggregate": "sum",
                  "scale": {
                    "reverse": true
                  },
                  "axis": {
                    "labels": false,
                    "title": null
                  }
                }
              },
              "opacity": {
                "condition": {
                  "test": {
                    "field": "_selected_",
                    "equal": "off"
                  },
                  "value": 0.3
                },
                "value": 1
              }
            }
          ]
        }
      ]
    }