我正在使用 vega lite 创建漏斗图,但是在将文本放置在每个条形图的中心时遇到问题。
以下是 vega lite 规格。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"encoding": {
"y": {"field": "department", "type": "nominal", "sort": "-x"},
"x": {
"field": "daily_total_login",
"type": "quantitative",
"stack": "center"
}
},
"layer": [
{
"mark": {"tooltip": true, "type": "bar"},
"encoding": {
"x": {
"field": "daily_total_login",
"type": "quantitative",
"stack": "center"
},
"color": {"field": "department", "type": "nominal", "legend": null}
}
},
{
"mark": {"type": "text"},
"encoding": {
"text": {"field": "daily_total_login", "type": "quantitative"}
},
}
],
"data": {
"values": [
{
"date": "2024-08-09",
"department": "A",
"daily_total_login": 277,
"daily_active_user": 87
},
{
"date": "2024-08-10",
"department": "B",
"daily_total_login": 36,
"daily_active_user": 9
},
{
"date": "2024-08-11",
"department": "C",
"daily_total_login": 39,
"daily_active_user": 14
},
{
"date": "2024-08-12",
"department": "D",
"daily_total_login": 124,
"daily_active_user": 51
},
]
},
"height": "container",
"width": "container"
}
有人可以建议我在上面的 vega lite 规范中做哪些更改,以便文本可以出现在每个条的中心吗?
1 个回答