Forum Discussion
Robert_BI
3 years agoFrequent Visitor
Stacked bar and line chart? (Charticulator)
PBI has a built-in “line and stacked column” visual, but I’d like to flip the axes. I don't think that can be done with the properties available. I’ve seen some custom visuals for purchase but I thou...
giammariam
Solution Sage
3 years agoIf you're open to using Deneb, below is a vega-lite spec that is pretty close to what you're after. You'll probably need to apply some tweaks once you put it up against real data. Let me know if you want any help getting it working.
Link to spec in vega-lite editor (you may have to manually re-apply the powerbi theme under the CONFIG tab)
spec and screenshot:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 710,
"height": 426,
"encoding": {
"y": {"field": "Category", "axis": {"labelAngle": 0}},
"color": {
"field": "Type",
"scale": {"domain": ["Value1", "Value2", "Target Value"]},
"legend": {"orient": "top", "title": null}
}
},
"layer": [
{
"mark": "bar",
"transform": [
{"filter": "datum['Type'] === 'Value1' || datum['Type'] === 'Value2'"}
],
"encoding": {
"x": {
"aggregate": "sum",
"field": "Value",
"title": "Sum of Value1 and Value2"
}
}
},
{
"mark": "line",
"transform": [{"filter": "datum['Type'] === 'Target Value'"}],
"encoding": {"x": {"aggregate": "sum", "field": "Value"}}
},
{
"mark": "point",
"encoding": {"x": {"aggregate": "sum", "field": "Target Value"}}
},
{
"mark": {"type": "point", "shape": "M 2.563 0 L 22.437 0 C 23.853 0 25 1.791 25 4 L 25 11.041 C 25 13.25 23.853 15.041 22.437 15.041 L 2.563 15.041 C 1.147 15.041 0 13.25 0 11.041 L 0 4 C 0 1.791 1.147 0 2.563 0 Z", "fill": "gainsboro", "size": 4},
"encoding": {
"x": {"aggregate": "sum", "field": "Target Value"},
"xOffset": {"value": 13},
"yOffset": {"value": 11}
}
},
{
"mark": "text",
"encoding": {
"text": {"field": "Target Value"},
"x": {"aggregate": "sum", "field": "Target Value"},
"xOffset": {"value": 25}
}
}
],
"transform": [
{"fold": ["Value1", "Value2", "Target Value"], "as": ["Type", "Value"]}
],
"data": {
"values": [
{"Category": "A", "Value1": "20", "Value2": "10", "Target Value": "25"},
{"Category": "B", "Value1": "40", "Value2": "30", "Target Value": "35"},
{"Category": "C", "Value1": "35", "Value2": "35", "Target Value": "30"},
{"Category": "D", "Value1": "15", "Value2": "5", "Target Value": "20"},
{"Category": "E", "Value1": "20", "Value2": "20", "Target Value": "25"},
{"Category": "F", "Value1": "15", "Value2": "5", "Target Value": "25"},
{"Category": "G", "Value1": "15", "Value2": "15", "Target Value": "20"},
{"Category": "H", "Value1": "25", "Value2": "25", "Target Value": "25"},
{"Category": "I", "Value1": "5", "Value2": "5", "Target Value": "30"},
{"Category": "J", "Value1": "10", "Value2": "10", "Target Value": "35"}
]
}
}