Skip to content

Instantly share code, notes, and snippets.

@Mark-Long-2023
Created October 22, 2023 10:49
Show Gist options
  • Select an option

  • Save Mark-Long-2023/4e57b19db3fe2e39965c96df582561dc to your computer and use it in GitHub Desktop.

Select an option

Save Mark-Long-2023/4e57b19db3fe2e39965c96df582561dc to your computer and use it in GitHub Desktop.
Deneb-Donut-KPI
{
"data": {"name": "dataset"},
"transform": [
{
"calculate": "datum['Index'] <= datum['_percToShow'] * 100 ? 1 : 0",
"as": "_color"
}
],
"layer": [
{
"description": "Outer donut for showing the KPI % measure",
"mark": {
"type": "arc",
"radius": 98,
"radius2": 80,
"padAngle": 0.016,
"opacity": {
"expr": "datum['_color'] == 1 ? 1 : 0.5"
}
},
"encoding": {
"theta": {
"field": "Size",
"type": "quantitative"
},
"color": {
"value": {
"expr": "datum['_color'] == 1 ? '#F0F4C3' : '#78909C'"
}
}
}
},
{
"description": "Inner circle line",
"mark": {
"type": "arc",
"radius": 75,
"radius2": 72,
"color": "#78909C",
"opacity": 0.5
},
"encoding": {
"theta": {
"aggregate": "sum",
"field": "Size",
"type": "quantitative"
}
}
},
{
"description": "KPI text inside the donut",
"mark": {
"type": "text",
"font": "DIN",
"fontSize": 40,
"fontWeight": "bold",
"color": "#F0F4C3"
},
"encoding": {
"text": {
"aggregate": "average",
"field": "_percToShow",
"type": "quantitative",
"format": "0.0%",
"formatType": "pbiFormat"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment