Vega-lite:图例中具有多重选择的饼图

问题描述 投票:0回答:1

我正在尝试在 vega-lite 中制作饼图,并能够选择要包含的类别。

这是我的第一次尝试(vega编辑器

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A simple pie chart with embedded data and multi-selection per category.",
  "data": {
    "values": [
      {"category": 1, "value": 4},
      {"category": 2, "value": 6},
      {"category": 3, "value": 10},
      {"category": 4, "value": 3},
      {"category": 5, "value": 7},
      {"category": 6, "value": 8}
    ]
  },
  "selection": {
    "category_select": {
      "type": "multi",
      "fields": ["category"],
      "bind": "legend"
    }
  },
  "transform": [{"filter": {"selection": "category_select"}}],
  "mark": {"type": "arc"},
  "encoding": {
    "theta": {"aggregate": "sum", "field": "value", "type": "quantitative"},
    "color": {"field": "category", "type": "nominal"}
  }
}

但是,当我选择一个

category
时,无法选择多个:

如何支持多类别选择,比如

2 and 4

json charts visualization pie-chart vega-lite
1个回答
0
投票

按住 Shift 键时可以进行多项选择。

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A simple pie chart with embedded data and multi-selection per category.",
  "data": {
    "values": [
      {"category": 1, "value": 4},
      {"category": 2, "value": 6},
      {"category": 3, "value": 10},
      {"category": 4, "value": 3},
      {"category": 5, "value": 7},
      {"category": 6, "value": 8}
    ]
  },
  "params": [{
    "name": "test",
    "select": {"type": "point", "fields": ["category"]},
    "bind": "legend"
  }],

  "mark": {"type": "arc"},
  "encoding": {
    "theta": {"aggregate": "sum", "field": "value", "type": "quantitative"},
    "color": {"field": "category", "type": "nominal"},
     "opacity": {
      "condition": {"param": "test", "value": 1},
      "value": 0.2
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.