0

我在 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>

4

1 回答 1

0

您可以通过选择(https://vega.github.io/vega-lite/docs/selection.html)和基于该选择的过滤器(https://vega.github.io/vega-lite/docs /filter.html#selection-predicate)。如果这不是一个选项,您将需要使用 Vega Signals 和 Vega View API。

于 2018-02-11T01:25:59.790 回答