简体   繁体   English

dc.js在多个值上添加过滤器

[英]dc.js add filter on multiple values

I am using dc.js, 我正在使用dc.js,

I want to add filter based on checkbox selection. 我想基于复选框选择添加过滤器。 Here is my scenario 这是我的情况

在此处输入图片说明

When i select checkboxes based on that i need filter. 当我选择基于此的复选框时,我需要过滤器。

Here is my code 这是我的代码

     var ndx = crossfilter(readData);

    var practiceDimension = ndx.dimension(function (d) {
            return d.practice_name;
        }); 

    $('#treeview input[name="practice_name[]"]:checked').each(function() {
            if(searchPracticeArray.indexOf($(this).val()) == -1)
                searchPracticeArray.push($(this).val());
                // If  I added searchPracticeArray as filter parameter then it's not working 
                // searchPracticeArray value are ['LPS','Mercy']

practiceDimension = practiceDimension.filter($(this).val());
                bubbleChart.filter($(this).val());       

        });

Currently i have two checkbox but it should be more then two and more. 目前,我有两个复选框,但应该多于两个。

You can filter a dimension based on a function. 您可以基于函数过滤维度。 I'd recommend doing this in your case. 我建议您这样做。 API documentation . API文档

However, keep in mind that this function will be run over every record in your data set at some point, so you'll want to just do the DOM query once and then save those values to an array within the scope of the function, then filter on that. 但是,请记住,此函数将在某个时候在数据集中的每个记录上运行,因此,您只需要执行一次DOM查询,然后将这些值保存到函数范围内的数组中,然后过滤。

Hi I have find some solutions like this 嗨,我找到了一些类似的解决方案

Here searchPracticeArray is array value which stored value based on selection. 这里searchPracticeArray是根据选择存储值的数组值。

if(searchPracticeArray.length > 0)
{
var practiceDimensionFilterData;
for(var d=0; d < searchPracticeArray.length; d++ )
{
    pract_name_search = searchPracticeArray[d].key;            
    practiceDimensionFilterData = readData.filter(function(d){ return(d.practice_name == pract_name_search)})            
    practiceDimension2[d] = practiceDimensionFilterData
    if(d > 0)
    {
    practiceDimension6 = practiceDimension2[0].concat(practiceDimension2[d])
    }
    else{
    practiceDimension6 = practiceDimension2[d];
    }
    bubbleChart.filter(pract_name_search);
}
ndx = crossfilter(practiceDimension6);  

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM