【问题标题】:Is it possible to get the filters applied on a particular dimension?是否可以将过滤器应用于特定维度?
【发布时间】:2023-03-04 15:27:01
【问题描述】:

是否可以将过滤器应用于特定维度?我需要通过单击按钮获取应用于一组 dc.js 图表的所有过滤器。

【问题讨论】:

    标签: javascript d3.js crossfilter dc.js


    【解决方案1】:

    我做了类似的事情。 但是,每次通过附加渲染器过滤图表时,我都没有使用按钮单击来获取值。

    您要查找的函数是 filters()

      yourChart.renderlet(function(chart) {
                dc.events.trigger(function() {
                    console.log(yourChart.filters())
                });
            })
    

    这将记录应用于图表维度的过滤器。

    【讨论】:

      【解决方案2】:

      您可以使用 chart.filterPrinter() 函数获取所选过滤器的值,该函数返回一个返回所选过滤器的字符串版本的函数。以下代码段将返回图表当前选定过滤器的字符串版本。

      chart.filterPrinter()(chart.filters()) 
      

      您甚至可以提供自己的 filterPrinter 函数进行自定义。

      您可以定义 on('filtered' 函数,该函数在每次图表上的过滤器值更改时触发。此函数接收图表作为第一个参数,并将当前过滤器选择/取消选择作为第二个参数。但是,您可以使用 chart.filters() 函数获取当前选定过滤器的完整列表。

      myChart.on('filtered', function(chart, filter) {
          var sel = chart.filterPrinter()(chart.filters());
          console.log('Selected Filters are: ' + sel);
      });
      

      【讨论】:

        猜你喜欢
        • 2012-10-05
        • 2011-11-01
        • 2017-02-02
        • 1970-01-01
        • 2014-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多