Skip to content

Instantly share code, notes, and snippets.

@PBI-DataVizzle
Created December 22, 2023 08:13
Show Gist options
  • Save PBI-DataVizzle/3dd07de40194eae582201984901ac62b to your computer and use it in GitHub Desktop.
Save PBI-DataVizzle/3dd07de40194eae582201984901ac62b to your computer and use it in GitHub Desktop.
vl_bar_hover_and_cf
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple bar chart with conditional coloring for the highest value.",
"data": {
"values": [
{"a": "A", "b": 28},
{"a": "B", "b": 55},
{"a": "C", "b": 43},
{"a": "G", "b": 19},
{"a": "H", "b": 87},
{"a": "I", "b": 52},
{"a": "D", "b": 91},
{"a": "E", "b": 81},
{"a": "F", "b": 53}
]
},
"params": [
{
"name": "hover",
"select": {"type": "point", "on": "mouseover", "clear": "mouseout"}
}
],
"transform": [
{
"window": [{"op": "max", "field": "b", "as": "max_b"}],
"frame": [null, null]
}
],
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "nominal", "axis": {"title": "Category"}},
"y": {"field": "b", "type": "quantitative", "axis": {"title": "Value"}},
"color": {
"condition": [
{"param": "hover", "empty": false, "value": "orange"},
{"test": "datum.b === datum.max_b", "value": "green"}
],
"value": "#404040"
},
"stroke": {
"condition": [
{"param": "hover", "empty": false, "value": "red"},
{"test": "datum.b === datum.max_b", "value": "black"}
],
"value": "#404040"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment