vega-lite:是否可以在没有参考图表的情况下只渲染图例?

vega-lite: is it possible to render only the legend without the reference chart?

我正在构建一个 HTML 页面的线框,其中有一些 vega-lite 图表。

有没有办法只渲染图表的图例?如果是,怎么办?

我不知道有什么内置方法可以仅显示图例,但您可以通过删除所有位置编码、将标记不透明度设置为零以及将视图 width/height 设置为0. 例如,这里有一种从 this Vega-Lite example:

生成图例的方法
{
  "data": {
    "url": "data/penguins.json"
  },
  "mark": {"type": "point", "opacity": 0},
  "encoding": {
    "color": {"field": "Species", "type": "nominal"},
    "shape": {"field": "Species", "type": "nominal"}
  },
  "config": {"view": {"width": 0, "height": 0}}
}