又一个星期,我要向你们提出另一个 Vega-lite 问题。 实际上在 Deneb 中创建 KPI 卡非常容易,但是让我头疼的是标记的位置。
正如您在下图中看到的那样,当增量为正时,它将线推到视觉的顶部,当增量为负时,则将线推到视觉的底部。我尝试设置固定轴来解决我的问题,但这并不正确,因为您的关键绩效指标 (KPI) 的增量范围大多数时候都不同。所以我不能给出一个范围 [-15%,15%],因为在 KPI 中,范围在 [-2%,2%] 之间,它基本上创建了一条平坦的线。而且我不想通过 KPI 单独设置轴 KPI。
更不用说在视觉上添加文本标签时,它可以从图片中推出。
您有什么办法可以解决这个问题吗?
非常感谢!
域可以根据您的数据动态计算为 +/- 10%。例如这个例子没有修复。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"x": 1, "y": 10},
{"x": 2, "y": 10},
{"x": 3, "y": 10},
{"x": 4, "y": 10},
{"x": 5, "y": 10},
{"x": 6, "y": 10},
{"x": 7, "y": 10}
]
},
"mark": {"type": "line", "point": true},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"}
}
}
这里是动态缩放的。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"x": 1, "y": 10},
{"x": 2, "y": 10},
{"x": 3, "y": 10},
{"x": 4, "y": 10},
{"x": 5, "y": 10},
{"x": 6, "y": 10},
{"x": 7, "y": 10}
]
},
"transform": [
{
"joinaggregate": [
{"op": "max", "field": "y", "as": "max"},
{"op": "min", "field": "y", "as": "min"}
]
},
{"calculate": "datum.max * 1.2", "as": "max"},
{"calculate": "datum.min * 0.8", "as": "min"}
],
"params": [
{"name": "max", "expr": "data('data_0')[0]['max']"},
{"name": "min", "expr": "data('data_0')[0]['min']"}
],
"mark": {"type": "line", "point": true},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": {"expr": "[min,max]"}}
}
}
}