multiple dimensions filter with comma separated values filter

721 views
Skip to first unread message

Niteen Munjani

unread,
Aug 5, 2016, 2:38:20 AM8/5/16
to dc-js user group
Hello Gordon and All, 

I have multiple filters on top of my chart as shown below




And Here is my code.

var data  = JSON.parse(response);  // my json data                             

var filterdata = crossfilter(data);
var all = filterdata.groupAll();

var dimensionMain = filterdata.dimension(function (d) { return [d.stageNumber, d.age]; }); // Used to draw chart x and y axis
var dimensionLocation = filterdata.dimension(function (d) { return d.geo; }); // used to filter location
var dimensionActivityId = filterdata.dimension(function (d) { return d.activityId; }); // used to filter activity 
var dimensionUserId = filterdata.dimension(function (d) { return d.userId; }); // used to filter user
var dimensionCreatedDate = filterdata.dimension(function (d) { return d.createdDate; }); // used to filter date


//on change of Location Picklist-  // This filter is working fine         
if(value){ // values from location picklist filter
dimensionGeo.filter(value);          
}else{      
dimensionGeo.filter(null);
}
dc.redrawAll(); 

//on change of Activities textbox, multiple activity search is comma separated
if(value){   // value from activity textbox
var arrValue = value.split(",");        
        if(arrValue.length > 1){ 
//activityIdsFilter.filter(null);
activityIdsFilter.filter([arrValue]); // mulitple values- THIS IS NOT WORKING.
}else{
activityIdsFilter.filter(value); // Single Values- This is working fine
}
}
else{      
activityIdsFilter.filter(null);
}
dc.redrawAll();

// my user filter code is same as activity filter. this filter is also not working with with multiple comma separated values
userIdsFilter.filter(value);           
                     
// on change of start date and end date - This filter is working fine         
createdDateFilter.filter(null);
createdDateFilter.filterRange([value1, value2]);
dc.redrawAll();


I have spent many hour behind this issue but not getting how to resolve this issue.

As per the suggestion by gordon I have filtered on chart as well but it wont work. please help me.

chart.filter(null);
chart.filter([arrValue]);
dc.redrawAll();

Regards
Nitin Munjani

Gordon Woodhull

unread,
Aug 5, 2016, 9:36:28 AM8/5/16
to dc-js-us...@googlegroups.com
As I said before, a crossfilter dimension won't take an array of individual values. It will take only a single value, or an array of size two specifying the bounds, or a predicate function.

So you'll have to supply a function if you want to select from a set.

Something like (untested):

activityIdsFilter.filter(function(x) { return arrValue.indexOf(x)!=-1; });

Cheers
Gordon
--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/123269b4-456a-4ae5-b3ee-64e5294ddcd4%40googlegroups.com.

Gordon Woodhull

unread,
Aug 5, 2016, 9:42:01 AM8/5/16
to dc.js user group
Message has been deleted

Gordon Woodhull

unread,
Aug 5, 2016, 11:44:02 AM8/5/16
to dc-js-us...@googlegroups.com
Weird that should do exactly the same thing. 
Glad you got it working!


On Aug 5, 2016, at 10:09 AM, Niteen Munjani <nitin....@gmail.com> wrote:

THANKS A LOT GORDON

Your solution worked for me.

Actually I had did the same thing with Filter function but it was not worked.

activityIdsFilter.filterfunction(function(x) { return arrValue.indexOf(x)!=-1; });

Anyway Thanks again.

Thanks & Regards
Niteen Munjani


To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-group+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-group+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "dc-js user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dc-js-user-group/KLEm3woIHRs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dc-js-user-group+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/644AB23E-4733-4C2A-8F66-B330DA364C9D%40woodhull.com.

--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages