按参考 table 中的选择过滤

Filter by selection from referenced table

我在 datasets 中有一个数据源,用于两个连接的图表。现在,当我单击左侧图表中的条形时,我想过滤右侧图表。查看动画 gif:

但事实并非如此。 单击 here 在 vega 编辑器中打开。 或者在此处查看规格::

{
  "config": {"view": {"width": 400, "height": 300}},
  "hconcat": [
    {
      "width": 100,
      "selection": {"SELECT": {"type": "single", "resolve": "global"}},
      "data": {"name": "table_data"},
      "mark": "bar",
      "encoding": {
        "x": {"type": "nominal", "field": "Major_Genre"},
        "y": {"aggregate": "count", "type": "quantitative"},
        "color": {"type": "nominal", "field": "Major_Genre"},
        "fillOpacity": {
          "condition": {"selection": "SELECT", "value": 1},
          "value": 0.3
        }
      }
    },
    {
      "width": 100,
      "data": {"name": "table_data"},
      "transform": [{"filter": {"selection": "SELECT"}}],
      "mark": "bar",
      "encoding": {
        "x": {"type": "nominal", "field": "Major_Genre"},
        "y": {"aggregate": "count", "type": "quantitative"},
        "color": {"type": "nominal", "field": "Major_Genre"}
      }
    }
  ],
  "datasets": {
    "table_data": [
      {
        "Title": "Cidade de Deus",
        "Major_Genre": "Drama",
        "Country_Origin": "Brazil"
      },
      {
        "Title": "Chocolate: Deep Dark Secrets",
        "Major_Genre": "Thriller/Suspense",
        "Country_Origin": "India"
      },
      {"Title": "Fiza", "Major_Genre": "Drama", "Country_Origin": "India"},
      {
        "Title": "First Love, Last Rites",
        "Major_Genre": "Drama",
        "Country_Origin": "United States"
      },
      {
        "Title": "Foolish",
        "Major_Genre": "Comedy",
        "Country_Origin": "United States"
      },
      {
        "Title": "I Married a Strange Person",
        "Major_Genre": "Comedy",
        "Country_Origin": "United States"
      }
    ]
  }
}

当您的选择涉及点组而不是单个点时,您需要提供明确的 fieldsencodings 参数来指定选择中包含哪些点。

在这种情况下,如果您通过以下方式之一指定您的选择,图表将按预期运行:

"selection": {"SELECT": {"type": "single", "fields": ["Major_Genre"], "resolve": "global"}}

"selection": {"SELECT": {"type": "single", "encodings": ["color"], "resolve": "global"}}

"selection": {"SELECT": {"type": "single", "encodings": ["x"], "resolve": "global"}}

这是实际的工作图表:(vega editor link)