cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tomwill
Microsoft
Microsoft

Deneb - change labelFontWeight for one value in an axis label

I have a text field ['Region'] with four values {Global, AMER, APAC, EMEA}. I have a simple bar chart and want the label to be bold only for 'Global'. I tried:

 

"encoding": {
    "y": {
      "field": "Region",
      "type": "nominal",
      "axis": {
        "offset": 10,
        "title": null,
       "labelFontWeight": {
         "condition": {"test": "datum['Region'] == 'Global'","value":"bold"},
            "value":"normal"
       }

 but there is no change to the label font weight. What is interesting is that I switched the result conditions, making the '==Global' "normal" and the else "bold" and it changed font weight on all the labels to bold. That leads me to believe that my condition is never being evaluated as true. Any ideas why? Is what I want to do - changing a signal value in an axis label - possible?

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @tomwill,

Fields are not exposed in the datum object for an axis label. You have access to either a label or value property in the backing datum and it's this that you need to inspect in your condition.

Something like the following should work:

  "labelFontWeight": {
    "condition": {
      "test": "datum['value'] == 'Global'",
      "value": "bold"
    },
    "value": "normal"
  }

I've replicated this in a chart I have open, specifying that the Wellington label be bold, as per the above approach and this seems as expected, e.g.:

dmp_0-1675801219693.png

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

3 REPLIES 3
dm-p
Super User
Super User

Hi @tomwill,

Fields are not exposed in the datum object for an axis label. You have access to either a label or value property in the backing datum and it's this that you need to inspect in your condition.

Something like the following should work:

  "labelFontWeight": {
    "condition": {
      "test": "datum['value'] == 'Global'",
      "value": "bold"
    },
    "value": "normal"
  }

I've replicated this in a chart I have open, specifying that the Wellington label be bold, as per the above approach and this seems as expected, e.g.:

dmp_0-1675801219693.png

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Thanks this worked. Very new to Deneb so still a lot of copy, paste, pray. I had used the 

"datum['Region']

structure to change data labels based on value but must be a difference in how datum works in a 'mark' block vs and 'encoding' block.

Glad it worked! Normally you would be correct in your assumption - you would refer to the field in a datum whenever it typically makes sense to do so (i.e. in a mark or most encoding channels), and was a good place to start. I was caught out by this initally, too 🙂

Axes are a special case because they potentially represent the normalisation of multiple series for a category, or could be continuous (and therefore use a different granularity for the number of displayed ticks than there are in your series). As such, the axis labels have their own (simpler) datum structure that is derived from the field you've encoded.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors