1 回答
TA贡献1784条经验 获得超7个赞
定义选择的方法"params"
目前是实验性的,并没有在当前版本的 Vega-Lite 中完全实现。
如果您想使用输入框来过滤数据,最直接的方法是遵循Vega-Lite 文档的输入元素绑定部分,并使用过滤器转换根据您创建的选择来过滤数据。
这是一个示例(在 Vega 编辑器中查看):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width": 800,
"height": 200,
"description": "Stock prices of 5 Tech Companies over Time.",
"data": {
"url": "https://raw.githubusercontent.com/BocongZhao823/My_First_Webpage-/main/data/rainfall_tidy.csv"
},
"selection": {
"city_selector": {
"type": "single",
"fields": ["city_name"],
"bind": {
"input": "select",
"options": [
null,
"Adelaide",
"Brisbane",
"Canberra",
"Melbourne",
"Perth",
"Sydney"
],
"labels": [
"Show All",
"Adelaide",
"Brisbane",
"Canberra",
"Melbourne",
"Perth",
"Sydney"
],
"name": "City Selection:"
}
}
},
"transform": [{"filter": {"selection": "city_selector"}}],
"mark": {"type": "line", "point": {"filled": false, "fill": "white"}},
"encoding": {
"x": {"timeUnit": "year", "field": "date"},
"y": {"aggregate": "mean", "field": "rainfall", "type": "quantitative"},
"color": {
"field": "city_name",
"type": "nominal",
"scale": {
"domain": [
"Adelaide",
"Brisbane",
"Canberra",
"Melbourne",
"Perth",
"Sydney"
]
}
}
}
}
添加回答
举报