Vega-Lite conditional colour based on values #8814
-
|
Hello all, I'm very new to the language and exploring Vega-lite to implement a solution at work. I'm trying to create a calendar heatmap using Deneb in power bi, based on percentage value for each day. The code I have is as below I'm not able to figure out a way to add conditions to this code. Please any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You can make use of a {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/cars.json"},
"mark": "rect",
"encoding": {
"y": {"field": "Origin", "type": "nominal"},
"x": {"field": "Cylinders", "type": "ordinal"},
"color": {
"aggregate": "mean",
"field": "Horsepower",
"scale": {
"type": "threshold",
"domain": [80, 110, 140],
"range": ["blue", "orange", "brown", "red"]
},
"type": "quantitative",
"legend":{"orient":"top"}
}
}
} |
Beta Was this translation helpful? Give feedback.


You can make use of a
thresholdincludingdomainandrangefor thescaledefinition:{ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "data": {"url": "data/cars.json"}, "mark": "rect", "encoding": { "y": {"field": "Origin", "type": "nominal"}, "x": {"field": "Cylinders", "type": "ordinal"}, "color": { "aggregate": "mean", "field": "Horsepower", "scale": { "type": "threshold", "domain": [80, 110, 140], "range": ["blue", "orange", "brown", "red"] }, "type": "quantitative", "legend":{"orient":"top"} } } }Open the Chart in the Vega Editor