Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
louloudigr
Frequent 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 line (country) the value that corresponds to the revenue per country but in total for all products. Is it possible?

 

 

4 REPLIES 4
lbendlin
Super User
Super User

Not with the standard visuals. Use Deneb or similar to create your own visual .

So, the only option I actually have is to create a custom visual. Do you think that i could it maybe using python code?

if that Python code renders the chart, yes.

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"
      }
    ]
  }
}

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.