[英]Vega-Lite: Is it possible to have images as labels in a line chart?
I want to have images as my axis labels.我想将图像作为我的轴标签。 I tried to use the image mark, but that did not work and that is kind of expected.
我尝试使用图像标记,但这不起作用,这在意料之中。 Label expression is also something I tried, but that did not work if I want it to be an image.
标签表达式也是我尝试过的,但如果我想要它是一个图像,那是行不通的。 What else could I tried or is it possible at all?
我还能尝试什么或者有什么可能?
Using the same technique in another answer , an image axis can be added via an extra layer:在另一个答案中使用相同的技术,可以通过额外的层添加图像轴:
{
"$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 ===== ===== 2021-07-20 =====
Your BarChart's x
encoding uses the x
field which is not evenly distributed, so it is misaligned.您的 BarChart 的
x
编码使用不均匀分布的x
字段,因此它未对齐。
If you do have the a
field shown in your editor, simplest way is to replace the encoding as "x": {"field": "a", "type": "ordinal", "axis": null}
如果您的编辑器中确实显示了
a
字段,最简单的方法是将编码替换为"x": {"field": "a", "type": "ordinal", "axis": null}
Even the a
field was not there, you may wanna add such a field for aligning, or even ordering, the image axis.即使
a
字段不存在,您也可能想要添加这样一个字段来对齐甚至排序图像轴。
The last resort I can think of is window
transform which is an overkill, but adds no extra value as well:我能想到的最后一招是
window
变换,这是一种矫枉过正,但也没有增加额外的价值:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.