79790081

Date: 2025-10-14 10:33:03
Score: 1.5
Natty:
Report link

I have a similar questing regarding Vega-lite in Power BI. I want to wrap the x-axis label after each ; but this solution didn't work for me. Even without using the Offset function.

        "labelExpr": "replace(datum.label, /;\\s*/g, '\\n')"

It removes the ; but doesn't wrap.

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"name": "dataset"},
  "encoding": {
    "x": {
      "field": "Bezeichner",
      "type": "nominal",
      "axis": {
        "title": "",
        "labelAngle": 0,
        "labelAlign": "center",
        "labelBaseline": "middle",
        "labelLineHeight": 12,
        "labelFontSize": 15, 
        "labelPadding": 10,
        "labelLimit": 500,
        "labelExpr": "replace(datum.label, /;\\s*/g, '\\n')"
      }
    }
  },
  "layer": [
    {
      "mark": {"type": "bar", "opacity": 1},
      "encoding": {
        "y": {
          "field": "LCC",
          "type": "quantitative",
          "axis": {"title": "", 
          "titleColor": "#118DFF",
           "orient": "right",
          "labelFontSize": 15,
          "labelFont": "Roboto", 
          "labelPadding": 10,
          "grid": true}
        },
        "xOffset": {"value": 57
      },
        "color": {"value": "#118DFF"},
        "tooltip": [
          {"field": "Bezeichner", "type": "nominal", "title": "Bezeichner"},
          {"field": "LCC", "type": "quantitative", "title": "LCC"},
          {"field": "LCA", "type": "quantitative", "title": "LCA"}
        ]
      }
    },
    {
      "mark": {"type": "bar", "opacity":1},
      "encoding": {
        "y": {
          "field": "LCA",
          "type": "quantitative",
          "axis": {
            "title": "",
            "orient": "left",
            "titleColor": "#AAE574",
            "grid": false,
            "labelFontSize": 15,
            "labelFont": "Roboto",
            "labelPadding": 10
          }
        },
        "xOffset": {"value": 8},
        "color": {"value": "#AAE574"},
        "tooltip": [
          {"field": "Bezeichner", "type": "nominal", "title": "Bezeichner"},
          {"field": "LCC", "type": "quantitative", "title": "LCC"},
          {"field": "LCA", "type": "quantitative", "title": "LCA"}
        ]
      }
    }
  ],
  "resolve": {"scale": {"y": "independent"}},
  "config": {
    "bar": {"size": 50},
    "scale": {
      "bandPaddingInner": 0.845,
      "bandPaddingOuter": 0.5
    
    }
  }
}
Reasons:
  • Blacklisted phrase (1): enter image description here
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Amy