Skip to content

Instantly share code, notes, and snippets.

@xoelop
Created May 10, 2021 12:21
Show Gist options
  • Select an option

  • Save xoelop/fa4b7ada1febf1e312b5f58421272ac1 to your computer and use it in GitHub Desktop.

Select an option

Save xoelop/fa4b7ada1febf1e312b5f58421272ac1 to your computer and use it in GitHub Desktop.
Stock charts with dynamic tooltip
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/stocks.csv"},
"width": 400,
"height": 300,
"encoding": {"x": {"field": "date", "type": "temporal"}},
"layer": [
{
"encoding": {
"color": {"field": "symbol", "type": "nominal"},
"y": {"field": "price", "type": "quantitative"}
},
"layer": [
{"mark": "line"},
{
"transform": [{"filter": {"param": "hover", "empty": false}}],
"mark": "point"
}
]
},
{
"transform": [{"pivot": "symbol", "value": "price", "groupby": ["date"]}],
"mark": {"type": "rule", "tooltip": {"content": "data"}},
"encoding": {
"opacity": {
"condition": {"value": 0.3, "param": "hover", "empty": false},
"value": 0
}
},
"params": [
{
"name": "hover",
"select": {
"type": "point",
"fields": ["date"],
"nearest": true,
"on": "mouseover",
"clear": "mouseout"
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment