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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DW868990
Helper IV
Helper IV

Vega Lite - Text color based on condition, so next white when darker background

Hi,

 

I am trying to get the Text color of the my Text Mark to be white when the value is over a 1000.

 

My vega-lite code is below and is not returning the color change, any help in what i am missing is appreciated.

 

{
"data": {"name": "dataset"},
"layer": [
{
"mark": "rect",
"encoding": {
"x": {"field": "Category",
"type": "nominal"
},
"y": {"field": "Sales", "type": "ordinal",
"bin":{"maxbins":10}},
"color": {"aggregate": "count", "field": "CustomerID"},
"tooltip": [
{"field": "Category", "type": "ordinal"},
{"aggregate": "count","field": "Metric", "type":"quantitative"}
]
}
},
{
"mark": {
"type": "text",
"dy":60,
"dx":-50
},
"encoding": {
"x": {"field": "Category",
"type": "nominal"
},
"y": {"field": "Sales", "type": "ordinal",
"bin":{"maxbins":10}},
"text": {"aggregate": "count","field": "CustomerID", "type": "quantitative"},
"color": {
"condition": {
"test": "datum['CustomerID'] < 1000",
"value": "white"},
"value": "black"
}
}
}
],
"config": {
"axis": {"grid": true, "tickBand": "extent"}
}
}

2 REPLIES 2
KerKol
Super User
Super User

I believe you need an aggregated value in the condition 

KerKol_1-1673506045700.png

 

 





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

Proud to be a Super User!




Greg_Deckler
Super User
Super User

@DW868990 I believe your encoding needs to be in your "mark" settings like this example from vega-lite documentation:

      "mark": "text",
      "encoding": {
        "text": {"field": "num_cars", "type": "quantitative"},
        "color": {
          "condition": {"test": "datum['num_cars'] < 40", "value": "black"},
          "value": "white"
        }

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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