Skip to content

Instantly share code, notes, and snippets.

@Dulani
Last active April 26, 2022 01:35
Show Gist options
  • Save Dulani/09f1635e965ea862f229184a717b82b2 to your computer and use it in GitHub Desktop.
Save Dulani/09f1635e965ea862f229184a717b82b2 to your computer and use it in GitHub Desktop.
Vega-Lite Chart with vertical rule movable with a slider.
/* Layering a verticle rule over existing data (with a control to boot) */
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"params": [
{
"name": "x1",
"value": 5,
"bind": {"input": "range", "min": 0, "max": 10, "step": 1}
}
],
"layer": [
{
"data": {
"values": [
{"a": 1, "b": 30},
{"a": 2, "b": 45},
{"a": 3, "b": 50},
{"a": 4, "b": 60},
{"a": 5, "b": 70},
{"a": 6, "b": 80},
{"a": 7, "b": 70},
{"a": 8, "b": 50},
{"a": 9, "b": 10}
]
},
"mark": {"type":"line", "size": 2},
"encoding": {
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative"}
}
},
{
"data": {"values": [{}]},
"mark": {"type": "rule", "strokeDash": [4, 4], "size": 2, "color": "grey"},
"encoding": {
"x": {"datum": {"expr": "x1"}, "type": "quantitative", "scale": {"domain": [0,10]}}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment