简体   繁体   English

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

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

I'm building a wireframe of an HTML page in which I have some vega-lite charts.我正在构建一个 HTML 页面的线框,其中有一些 vega-lite 图表。

Is there a way to render only the legend of a chart?有没有办法只渲染图表的图例? If yes, how to?如果是,怎么做?

I don't know of a built-in way to display only the legend, but you can hack it by removing all positional encodings, setting the mark opacity to zero, and setting the view width/height to 0. For example, here is a way to generate just the legend from this Vega-Lite example :我不知道仅显示图例的内置方法,但您可以通过删除所有位置编码、将标记不透明度设置为零并将视图宽度/高度设置为 0 来破解它。例如,这里是一种从这个 Vega-Lite 示例中生成图例的方法:

{
  "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}}
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM