如何在 Vega Lite 中将图例底部中间对齐?

Arv*_*esh 2 vega-lite

在 Vega Lite 中,我试图将我的图例与该图表的中间对齐。我需要类似anchor图例的参数之类的东西,但我只能找到titleAnchor.

带图例的图表

"legend": {
        "title": "Signed NDA",
        "orient": "bottom",
        "titleAnchor": "middle"
      }
Run Code Online (Sandbox Code Playgroud)

这就是我的传奇现在的样子。有人知道怎么做吗?

ehu*_*udk 6

这实际上可以在 Vega 5.0 中实现,即图例布局属性,方法是将图例布局配置中的anchor属性设置为, 。"middle"

layoutVega-Lite 似乎尚未直接支持提供,但可以将layout定义从 Vega-Lite 传播到 Vega。根据 Jake 在Vega-Lite 编辑器
中的回答:

{
  "data": {"url": "data/cars.json"},
  "mark": "point",
  "encoding": {
    "x": {"field": "Horsepower", "type": "quantitative"},
    "y": {"field": "Miles_per_Gallon", "type": "quantitative"},
    "color": {"field": "Origin", "type": "nominal"}
  },
  "height": 300,
  "width": 400,
  
  "config": {
    "legend": {"orient": "bottom", "layout": {"bottom": {"anchor": "middle"}}}
  }
}
Run Code Online (Sandbox Code Playgroud)

在最后指定config基本上可以让您自定义orient "bottom"应该的外观。

在此输入图像描述