0

Is it possible to manage density of data labels (text marks) similarly to what the labelOverlap setting does with the axis labels? Ideally, I'd like them to be in sync.

Visual in Deneb/PowerBI Dataset

{
  "data": {"name": "dataset"},
  "encoding": {
    "x": {
      "field": "Date",
      "type": "nominal",
      "axis": {"labelOverlap": true}
    },
    "y": {
      "aggregate": "sum",
      "field": "Sum of Value"
    }
  },
  "layer": [
    {"mark": {"type": "bar"}},
    {
      "mark": {
        "type": "text",
        "baseline": "top",
        "align": "left",
        "dx": 5,
        "dy": -3,
        "fontSize": 9,
        "angle": 270
      },
      "encoding": {
        "text": {"field": "Sum of Value"}
      }
    }
  ]
}
VladB
  • 59
  • 6
  • Can you post a working spec with sample data? – Davide Bacci Mar 02 '23 at 16:39
  • Added the spec (from Deneb) and pictures of the visual and a dataset. The dataset is quite long, so I didn't include it here. – VladB Mar 02 '23 at 17:30
  • You are saying where to place those text marks in the spec - they're not automated. You can write a transform to place them every other value if that helps or use some other logic like only show text values over a certain amount. You can control it all but just need to write the logic. What logic do you want to use to control it? – Davide Bacci Mar 02 '23 at 17:38
  • You have a y axis with labels on - why not remove the data bar labels completely? – Davide Bacci Mar 02 '23 at 17:39
  • This is just a sample / test. The real visuals are much complex and will distract from the main point if I post it here. Re: using transforms. Sure, I can do that. The question is how to match X axis labels when {"labelOverlap": true} – VladB Mar 02 '23 at 17:52
  • 1
    The advice is the same though. You can control the labels with whatever logic you choose. You just need to decide what that is and then set a flag to display or hide the text mark. It is a common requirement but you need to specify the logic. – Davide Bacci Mar 02 '23 at 17:54
  • So, it looks like Vega Lite can't control text marks the same (or similar) way as it does with axis labels via {"labelOverlap": true}, correct? – VladB Mar 02 '23 at 17:58
  • 1
    That's correct. – Davide Bacci Mar 02 '23 at 18:08

1 Answers1

0

Here is a prototype solutions that I came up with.

Within PowerBI, I'll simply use a hardcoded threshold like "if the number of bars is more than 100, then hide every other label". If will be sufficient for my use case.

Vega-lite editor

Stacked Bar Chart - All Labels Stacked Bar Chart - 1 out of 2 Stacked Bar Chart - 2 out of 3

VladB
  • 59
  • 6