You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Power BI中Deneb图表的brush功能过滤其他视觉对象

问题

在Power BI中,左侧放置了包含折线标记和条形标记的Deneb图表,右侧是一个表格。按住Ctrl键逐个点击2005至2008年的条形时,右侧表格会被过滤;但希望通过brush(框选)功能实现相同的过滤效果,目前该功能无法生效。

原始Deneb配置代码

{
  "data": {
    "name": "dataset"
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    }
  },
  "layer": [
    {
      "mark": "line",
      "encoding": {
        "y": {
          "field": "world_gdp",
          "type": "quantitative"
        }
      }
    },
    {
      "mark": {"type": "bar", "width": 10},
      "encoding": {
        "y": {
          "value": 200
        },
        "y2": {
          "value": 210
        }
      },
      "params": [
        {
          "name": "brush_years",
          "select": {
            "type": "interval",
            "encodings": [
              "x"
            ]
          }
        }
      ]
    }
  ]
}

所用CSV数据集

year,world_gdp,name,description,country
2000,33.5,Human Genome Project,Completion of the first full sequence of the human genome,USA
2001,31.7,iPod invention,Launch of the first Apple iPod,USA
2002,34.9,Boeing 777-300ER,Introduction of the Boeing 777-300ER,USA
2003,38.7,Concorde retirement,End of the Concorde supersonic passenger flights,France/UK
2004,44.2,Facebook launch,Launch of the social networking platform Facebook,USA
2005,50.6,Deep Impact mission,NASA's Deep Impact mission collides with comet Tempel 1,USA
2006,55.4,Dwarf planet definition,Pluto reclassified as a dwarf planet by the IAU,International
2007,65.6,iPhone release,Introduction of the first Apple iPhone,USA
2008,73.1,Large Hadron Collider,First operation of the Large Hadron Collider,Switzerland
2009,60.9,Wolf-Rayet Star discovery,Discovery of the largest known star in the Milky Way,Chile
2010,66.2,Graphene,Andre Geim and Konstantin Novoselov awarded the Nobel Prize for Graphene,UK
2011,73.3,Curiosity rover,Launch of NASA's Curiosity Mars rover,USA
2012,76.3,Higgs boson discovery,Confirmation of the existence of the Higgs boson particle,Switzerland
2013,80.7,COSMOS TV series revival,Reboot of the scientific documentary series COSMOS,USA
2014,83.8,CRISPR-Cas9,CRISPR-Cas9 gene-editing technology gains prominence,USA
2015,77.8,Gravitational waves detection,First detection of gravitational waves by LIGO,USA
2016,79.6,Proxima b discovery,Discovery of potentially habitable exoplanet Proxima b,Chile
2017,87.3,First image of a black hole,First-ever image of a black hole captured,International
2018,88.2,AI defeat at Go,AI defeats top human player in the game of Go,USA/China
2019,86.7,Quantum supremacy,Google's claim of quantum supremacy,USA
2020,86.4,COVID-19 vaccines,Development and rollout of the first COVID-19 vaccines,Global
2021,87.6,James Webb Space Telescope,Launch of the James Webb Space Telescope,USA/Europe
2022,85.9,Human genome fully sequenced,Completion of the first fully sequenced human genome,USA
2023,84.5,Artemis I mission,Uncrewed mission to test NASA's Artemis I spacecraft around the moon,USA
解决方案

要实现brush框选过滤Power BI表格,需调整Deneb配置中的参数层级和关联逻辑,修改后的完整代码如下:

{
  "data": {
    "name": "dataset"
  },
  "params": [
    {
      "name": "brush_years",
      "select": {
        "type": "interval",
        "encodings": ["x"],
        "fields": ["year"]
      },
      "bind": "scales"
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    }
  },
  "layer": [
    {
      "mark": "line",
      "encoding": {
        "y": {
          "field": "world_gdp",
          "type": "quantitative"
        }
      }
    },
    {
      "mark": {"type": "bar", "width": 10},
      "encoding": {
        "y": {
          "value": 200
        },
        "y2": {
          "value": 210
        },
        "opacity": {
          "condition": {
            "param": "brush_years",
            "value": 1
          },
          "value": 0.3
        }
      }
    }
  ]
}

修改说明

  1. 调整参数层级:将params从条形图层内部移至图表根层级,确保brush选择的上下文能被Power BI的筛选系统识别。
  2. 关联数据字段:在select配置中添加fields: ["year"],明确brush选择对应的数据字段,让Power BI能正确映射筛选条件。
  3. 绑定交互上下文:添加bind: "scales",建立brush选择与图表刻度的关联,确保框选范围转化为有效的筛选值。
  4. 添加选中反馈(可选):给条形标记增加opacity编码,未选中时透明度降低,选中时恢复,提升用户交互体验。

完成上述修改后,使用brush框选2005-2008年的条形区域,右侧表格会自动过滤出对应年份的数据,实现和Ctrl点击一致的筛选效果。

内容的提问来源于stack exchange,提问作者Vlad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 19:14:55