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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
tomwill
Employee
Employee

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors