我在 Vega lite 中有以下代码。我想将变换过滤器 1850 更改为 2000。请建议我如何更改架构的变换过滤器。如果可能的话,是否有动态数据更改和更新视图的示例示例。人口数据来自 https://vega.github.io/editor/data/population.json
var yourVlSpec = {
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {
"url": "https://vega.github.io/editor/data/population.json",
"format": {
"type": "json"
}
},
"transform": [
{
"filter": "datum.year == 1850"
}
],
"mark": "bar",
"encoding": {
"x": {
"aggregate": "sum",
"field": "people",
"type": "quantitative",
"axis": {
"title": "population"
}
}
},
"config": {
"scale": {
"rangeStep": 21
}
}
}
vegaEmbed('#vis', yourVlSpec).then(function (result) {
result.spec.transform[0] = '{filter: "datum.year == 2000"}';
}).catch(console.error);
<html>
<head>
<title>Embedding Vega-Lite</title>
<script src="https://cdn.jsdelivr.net/npm/vega@3.0.10"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2.1.2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3.0.0"></script>
</head>
<body>
<div id="vis"></div>
<div id="view"></div>
</body>
</html>