Forum Discussion
Deneb data label help
- 2 years ago
Hi Doug7983,
Apologies - I cribbed from Lutz's spec as it was already pretty-printed, so I didn't know about the formatting requirements for the bars. I've taken yours and applied the changes you asked for. Here's how it looks now:
Note that I needed to remove the redundant sort operations from the x-encoding in each bar's layer as these can be set at the top level and were messing with the sorts lower down. Because this is a layered spec, an op (aggregate) property is needed, a quirk of Vega-Lite. I'd also recommend setting shared encoding properties at as high a level as possible and letting dependent layers inherit where possible rather than repeating. Not that they don't work if you don't, but they can trip you up if one mark differs from another and they're sharing the same encoding channel. This can also help make your spec easier to read. maintain and debug 👌
Here's the amended spec:
{ "data": {"name": "dataset"}, "layer": [ { "mark": { "type": "bar", "opacity": 0.3, "tooltip": true }, "encoding": { "x": {"field": "ModelKey"}, "y": {"field": "Min of MAPEVl"}, "color": {"value": "lightgrey"} } }, { "mark": { "type": "bar", "tooltip": true }, "encoding": { "x": {"field": "ModelKey"}, "y": { "field": "Min of MAPEVl__highlight" }, "color": { "condition": { "test": "datum['Min of MAPEVl__highlight'] !== null", "value": "steelblue" }, "value": "lightgrey" } } }, { "transform": [ { "filter": "datum['Min of MAPEVl__highlight'] !== null && datum['Min of MAPEVl__highlightStatus'] !== 'neutral'" } ], "mark": { "type": "text", "baseline": "bottom", "dy": -5 }, "encoding": { "text": { "field": "Min of MAPEVl__highlight", "format": ".2f" } } } ], "encoding": { "x": { "field": "ModelKey", "type": "nominal", "sort": { "field": "Min of MAPEVl", "order": "ascending", "op": "min" }, "axis": null }, "y": { "field": "Min of MAPEVl", "type": "quantitative", "axis": {"title": "Min of MAPEVl"} } } }And thanks for using Deneb! I'm glad you find it useful 🙂
Cheers,
Daniel
Hi dm-p,
Thank you for your reply. Assuming that I could restore the sorting as you suggested, is it possible to also add the highlighting of the selected bar back in? It helps the selection stand out more than just a data label alone.
Again, thanks for the help. I'm still in the fumbling around stage with Deneb, but it has helped me deliver visuals that just aren't possible with the default PBI options.
Hi Doug7983,
Apologies - I cribbed from Lutz's spec as it was already pretty-printed, so I didn't know about the formatting requirements for the bars. I've taken yours and applied the changes you asked for. Here's how it looks now:
Note that I needed to remove the redundant sort operations from the x-encoding in each bar's layer as these can be set at the top level and were messing with the sorts lower down. Because this is a layered spec, an op (aggregate) property is needed, a quirk of Vega-Lite. I'd also recommend setting shared encoding properties at as high a level as possible and letting dependent layers inherit where possible rather than repeating. Not that they don't work if you don't, but they can trip you up if one mark differs from another and they're sharing the same encoding channel. This can also help make your spec easier to read. maintain and debug 👌
Here's the amended spec:
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "bar",
"opacity": 0.3,
"tooltip": true
},
"encoding": {
"x": {"field": "ModelKey"},
"y": {"field": "Min of MAPEVl"},
"color": {"value": "lightgrey"}
}
},
{
"mark": {
"type": "bar",
"tooltip": true
},
"encoding": {
"x": {"field": "ModelKey"},
"y": {
"field": "Min of MAPEVl__highlight"
},
"color": {
"condition": {
"test": "datum['Min of MAPEVl__highlight'] !== null",
"value": "steelblue"
},
"value": "lightgrey"
}
}
},
{
"transform": [
{
"filter": "datum['Min of MAPEVl__highlight'] !== null && datum['Min of MAPEVl__highlightStatus'] !== 'neutral'"
}
],
"mark": {
"type": "text",
"baseline": "bottom",
"dy": -5
},
"encoding": {
"text": {
"field": "Min of MAPEVl__highlight",
"format": ".2f"
}
}
}
],
"encoding": {
"x": {
"field": "ModelKey",
"type": "nominal",
"sort": {
"field": "Min of MAPEVl",
"order": "ascending",
"op": "min"
},
"axis": null
},
"y": {
"field": "Min of MAPEVl",
"type": "quantitative",
"axis": {"title": "Min of MAPEVl"}
}
}
}
And thanks for using Deneb! I'm glad you find it useful 🙂
Cheers,
Daniel
- Doug79832 years agoHelper II
dm-p This is exactly what I wanted to accomplish. Thanks so much.
For others who may come across this thread and wonder why I needed Deneb for a fairly standard visual (and for your knowledge on how people are using your tool): The visual is meant to help users see at a glance where a particular selection falls in the distribution of available options. The native Power BI column chart's scrollbars were a major obstacle to that.
Thanks, Daniel. And thanks for creating Deneb!