您需要将“最近”属性添加到选择参数中。此处记录了针对您的用例的一些限制和解决方法。
https://vega.github.io/vega-lite/docs/selection.html#nearest https://vega.github.io/vega-lite/docs/selection.html#nearest
Edit:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Stock prices of 5 Tech Companies over Time.",
"data": {"url": "data/stocks.csv"},
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"},
"color": {"field": "symbol", "type": "nominal"}
},
"layer": [
{"mark": {"type": "line"}},
{
"params": [
{
"name": "paintbrush",
"select": {"type": "point", "on": "mouseover", "nearest": true}
}
],
"mark": {"type": "circle", "tooltip": true},
"encoding": {
"color": {
"condition": {
"param": "paintbrush",
"field": "symbol",
"type": "ordinal"
},
"value": "transparent"
},
"size": {"value": 75}
}
}
]
}