Forum Discussion
louloudigr
3 years agoFrequent Visitor
Data labels in a 100% stacked bar chart / adding a value
Hello, I have a 100% stacked bar chart that displays per country the product sales. (I've reduced my products in the top 3, so that for each country i have these only). I want to add next to each...
lbendlin
Super User
3 years agoif that Python code renders the chart, yes.
louloudigr
3 years agoFrequent Visitor
I tried this code, but it does not display the visual as I expect:
I want in axe Y the countries and then display the apples, lemons and oranges in a 100% stacked bar chart. At the end of each bar to display as label the revenue for each country
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"name": "dataset"},
"transform": [
{
"calculate": "datum['apples'] + datum['oranges'] + datum.lemons",
"as": "total"
},
{
"stack": "total",
"as": ["bottom", "top"]
}
],
"mark": "bar",
"encoding": {
"y": {
"field": "Country",
"type": "nominal"
},
"x": {
"field": [
"apples",
"oranges",
"lemons"
],
"type": "quantitative",
"stack": "normalize",
"axis": {"format": ".0%"}
},
"color": {
"field": "revenue",
"scale": {"scheme": "redblue"}
},
"opacity": {
"condition": {
"test": {
"field": "__selected__",
"equal": "off"
},
"value": 0.3
},
"value": 1
},
"tooltip": [
{
"field": "apples",
"title": "apples"
},
{
"field": "oranges",
"title": "oranges"
},
{
"field": "lemons",
"title": "lemons"
}
]
}
}