首页 > 解决方案 > 如何在 Vega Lite 中底部中间对齐图例?

问题描述

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

带图例的图表

"legend": {
        "title": "Signed NDA",
        "orient": "bottom",
        "titleAnchor": "middle"
      }

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

标签: vega-lite

解决方案


没有将图例锚定在底部中心的选项,但您可以设置orient: "none"和使用legendXlegendY属性将其准确定位到您想要的位置。例如(维加编辑器):

{
  "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",
      "legend": {
        "orient": "none",
        "direction": "horizontal",
        "legendX": 120,
        "legendY": 340,
        "title": null
      }
    }
  },
  "height": 300,
  "width": 400
}

在此处输入图像描述


推荐阅读