Search code examples
vega-lite

Line wrap for horizontal legends in vega-lite


Is there a way to make the labels in a legend with horizontal direction wrap? I made a simple example wtih the cars dataset where i transformed the categtories to generate longer strings in the Vega Editor: enter image description here

Suppose I have more categories but also want to put the legend at the top/bottom to provide more horizontal space for the chart area.


Solution

  • Use the columns property of legend:

      {
        "legend": {
        "orient": "top",
        "direction": "horizontal",
        "columns": 2
      }