tom*_*sek 3 visualization powerbi vega-lite powerbi-desktop deneb
又一周,另一个 Vega-lite 问题我\xc2\xb4m 转向你们。\n它\xc2\xb4s 实际上在 Deneb 中创建 KPI 卡非常容易,但是 \xc2\xb4s 让我头痛的是标记的定位。
\n正如您在下图中看到的那样,当增量为正时,\xc2\xb4 会将线推到视觉效果的顶部,而当增量为负时,则将线推到底部。I\xc2\xb4ve 尝试设置固定轴来解决我的问题,但这并不正确,因为您的 KPI 的增量范围大多数时候都不同。因此,我可以\xc2\xb4t 设置一个范围 [-15%,15%],因为在 KPI 中,范围在 [-2%,2%] 之间,\xc2\xb4s 基本上创建一条平坦的线。而且我不想\xc2\xb4t想通过KPI单独设置轴KPI。
\n更不用说向视觉效果添加文本标签时,它可以从图片中推出。
\n您有什么办法可以解决这个问题吗?
\n多谢!
\n\n该域可以根据您的数据动态计算为 +/- 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"}
}
}
Run Code Online (Sandbox Code Playgroud)
这里它是动态缩放的。
{
"$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]"}}
}
}
}
Run Code Online (Sandbox Code Playgroud)