Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text wrapping axis tick labels breaks stacked bar chart #9441

Open
danlewis85 opened this issue Sep 24, 2024 · 0 comments
Open

Text wrapping axis tick labels breaks stacked bar chart #9441

danlewis85 opened this issue Sep 24, 2024 · 0 comments
Labels

Comments

@danlewis85
Copy link

danlewis85 commented Sep 24, 2024

Bug Description

I want to create a stacked bar chart, but my axis labels are long so ideally I'd like to wrap the text.

Here is the desired output without wrapping vega editor link.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 300
    }
  },
  "data": {
    "name": "data-e8dbb78e76226aa05b2ea6ce39724b21"
  },
  "datasets": {
    "data-e8dbb78e76226aa05b2ea6ce39724b21": [
      {
        "response": "yes",
        "value": 80,
        "variable": "Really long variable name number 1"
      },
      {
        "response": "maybe",
        "value": 40,
        "variable": "Really long variable name number 1"
      },
      {
        "response": "no",
        "value": 12,
        "variable": "Really long variable name number 1"
      },
      {
        "response": "yes",
        "value": 60,
        "variable": "Seriously long variable name number 2"
      },
      {
        "response": "maybe",
        "value": 50,
        "variable": "Seriously long variable name number 2"
      },
      {
        "response": "no",
        "value": 22,
        "variable": "Seriously long variable name number 2"
      }
    ]
  },
  "encoding": {
    "color": {
      "field": "response",
      "sort": [
        "yes",
        "maybe",
        "no"
      ],
      "type": "ordinal"
    },
    "order": {
      "field": "color_response_sort_index",
      "type": "quantitative"
    },
    "x": {
      "field": "value",
      "stack": "normalize",
      "title": "Percentage of Visitors",
      "type": "quantitative"
    },
    "y": {
      "axis": {
        "labelLimit": 350
      },
      "field": "variable",
      "title": "",
      "type": "nominal"
    }
  },
  "height": 200,
  "mark": {
    "type": "bar"
  },
  "width": 500
}

Now if I wrap the 'variable' text over multiple lines using a collection, the stacked bars break as in this example vega editor link:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 300
    }
  },
  "data": {
    "name": "data-00e711a020ed06f24288e7f5cd8c2863"
  },
  "datasets": {
    "data-00e711a020ed06f24288e7f5cd8c2863": [
      {
        "response": "yes",
        "value": 80,
        "variable": [
          "Really long variable",
          "name number 1"
        ]
      },
      {
        "response": "maybe",
        "value": 40,
        "variable": [
          "Really long variable",
          "name number 1"
        ]
      },
      {
        "response": "no",
        "value": 12,
        "variable": [
          "Really long variable",
          "name number 1"
        ]
      },
      {
        "response": "yes",
        "value": 60,
        "variable": [
          "Seriously long",
          "variable name number",
          "2"
        ]
      },
      {
        "response": "maybe",
        "value": 50,
        "variable": [
          "Seriously long",
          "variable name number",
          "2"
        ]
      },
      {
        "response": "no",
        "value": 22,
        "variable": [
          "Seriously long",
          "variable name number",
          "2"
        ]
      }
    ]
  },
  "encoding": {
    "color": {
      "field": "response",
      "sort": [
        "yes",
        "maybe",
        "no"
      ],
      "type": "ordinal"
    },
    "order": {
      "field": "color_response_sort_index",
      "type": "quantitative"
    },
    "x": {
      "field": "value",
      "stack": "normalize",
      "title": "Percentage of Visitors",
      "type": "quantitative"
    },
    "y": {
      "axis": {
        "labelLimit": 350
      },
      "field": "variable",
      "title": "",
      "type": "nominal"
    }
  },
  "height": 200,
  "mark": {
    "type": "bar"
  },
  "width": 500
}

Is there any way I can work around this? I'd really like to be able to wrap the label text.

Checklist

  • [x ] I checked for duplicate issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant