代码:Link
对我来说,“83%”的值似乎是硬编码的,我希望根据 Power BI 测量值进行调整。我觉得我真的错过了一些东西,但是有没有办法导入 JSON,调整代码,然后拥有动态视觉效果?
在这个屏幕截图中,我尝试解释我的意思: deneb visual example
我尝试删除“信号”部分并将数据绑定(bind)到数据集,但无法使其工作。
感谢您的任何提示:)
最佳答案
这是我的代码😀。您可以在此处查看其他示例:https://github.com/PBI-David/Deneb-Showcase
要使其在 Deneb 中发挥作用,请创建一个名为 myMeasure 的度量并将其放入 Deneb 中的字段中。然后添加以下代码。
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 400,
"height": 400,
"padding": 50,
"background": "#222431",
"signals": [
{
"name": "textGradient",
"update": "{gradient: 'linear', stops: [{offset: 0, color: '#14d8cc'}, {offset: 1, color: '#4c8bee'}]}"
},
{
"name": "percent",
"update": "0",
"on": [
{
"events": {
"type": "timer",
"throttle": 0
},
"update": "round(data('dataset')[0]['myMeasure'])"
}
]
}
],
"data": [
{"name": "dataset"},
{
"name": "back",
"values": [],
"transform": [
{
"type": "sequence",
"start": 0,
"stop": 100,
"step": 1,
"as": "val"
},
{
"type": "formula",
"expr": "1",
"as": "t"
},
{
"type": "pie",
"field": "t",
"startAngle": {"signal": "0"},
"endAngle": {"signal": "2*PI"}
}
]
},
{
"name": "front",
"values": [],
"transform": [
{
"type": "sequence",
"start": 0,
"stop": {"signal": "percent"},
"step": 1,
"as": "val"
},
{
"type": "formula",
"expr": "1",
"as": "t"
},
{
"type": "pie",
"field": "t",
"startAngle": {"signal": "0"},
"endAngle": {
"signal": "((2*PI)/100)*percent"
}
}
]
}
],
"scales": [
{
"name": "color",
"type": "linear",
"domain": {
"data": "back",
"field": "val"
},
"range": [
"#14d8cc",
"#4c8bee",
"#6567ee",
"#b533d2",
"#b533d2"
]
}
],
"marks": [
{
"type": "arc",
"from": {"data": "back"},
"encode": {
"enter": {
"fill": {"value": "#3f424e"},
"x": {"signal": "width / 2"},
"y": {"signal": "height / 2"}
},
"update": {
"startAngle": {
"field": "startAngle"
},
"endAngle": {
"field": "endAngle"
},
"padAngle": {
"signal": "0.015"
},
"innerRadius": {
"signal": "(width / 2)-15"
},
"outerRadius": {
"signal": "width / 2"
}
}
}
},
{
"type": "arc",
"from": {"data": "front"},
"encode": {
"enter": {
"fill": {
"scale": "color",
"field": "val"
},
"x": {"signal": "width / 2"},
"y": {"signal": "height / 2"}
},
"update": {
"startAngle": {
"field": "startAngle"
},
"endAngle": {
"field": "endAngle"
},
"padAngle": {
"signal": "0.015"
},
"innerRadius": {
"signal": "(width / 2)-15"
},
"outerRadius": {
"signal": "width / 2"
}
}
}
},
{
"type": "arc",
"data": [{"a": 1}],
"encode": {
"enter": {
"fill": {"value": "#3f424e"},
"x": {"signal": "width / 2"},
"y": {"signal": "height / 2"}
},
"update": {
"startAngle": {"signal": "0"},
"endAngle": {
"signal": "2*PI"
},
"innerRadius": {
"signal": "(width / 2)-25"
},
"outerRadius": {
"signal": "(width / 2)-20"
}
}
}
},
{
"type": "text",
"data": [{}],
"encode": {
"update": {
"text": {
"signal": "percent + '%'"
},
"align": {"value": "center"},
"fontWeight": {
"value": "bold"
},
"fill": {
"signal": "textGradient"
},
"x": {"signal": "width /2"},
"y": {"signal": "width /2"},
"dy": {"value": 10},
"fontSize": {"value": 70}
}
}
},
{
"type": "text",
"data": [{}],
"encode": {
"update": {
"text": {
"value": "on target"
},
"align": {"value": "center"},
"fontWeight": {
"value": "bold"
},
"fill": {"value": "#9092a1"},
"x": {"signal": "width /2"},
"y": {"signal": "width /2"},
"dy": {"value": 40},
"fontSize": {"value": 30}
}
}
}
]
}
关于powerbi - 将 Vega (Deneb) 仪表转换为在 PowerBI 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75881301/