[英]Vega-Lite: Is it possible to have images as labels in a line chart?
在另一个答案中使用相同的技术,可以通过额外的层添加图像轴:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"x": 0.5, "y": 0.5, "img": "data/ffox.png"},
{"x": 1.5, "y": 1.5, "img": "data/gimp.png"},
{"x": 2.5, "y": 2.5, "img": "data/7zip.png"}
]
},
"layer": [{
"mark": {"type": "image", "width": 50, "height": 50},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"},
"url": {"field": "img", "type": "nominal"}
}
}, {
"transform": [{"calculate": "-.2", "as": "axis"}],
"mark": {"type": "image", "width": 25, "height": 25},
"encoding": {
"x": {"field": "x", "type": "quantitative", "axis":{"labelExpr": "", "title": null}},
"y": {"field": "axis", "type": "quantitative", "scale": {"domain": [0, 2.5]}},
"url": {"field": "img", "type": "nominal"}
}
}],
"resolve": {"scale": {"y": "shared"}}
}
===== 2021-07-20 =====
您的 BarChart 的x
编码使用不均匀分布的x
字段,因此它未对齐。
如果您的编辑器中确实显示了a
字段,最简单的方法是将编码替换为"x": {"field": "a", "type": "ordinal", "axis": null}
即使a
字段不存在,您也可能想要添加这样一个字段来对齐甚至排序图像轴。
我能想到的最后一招是window
变换,这是一种矫枉过正,但也没有增加额外的价值:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.