Skip to content Skip to sidebar Skip to footer

Cross-filter Using Drop Downs

I have two drop-downs. I want that whenever a selection is made in either of the drop-downs, a function called intersect be called which in turn calls the functions loadData and lo

Solution 1:

I dont know what's so difficult here...

I want that whenever a selection is made in either of the drop-downs, a function called intersect be called which in turn calls the functions loadData and loadData1.

<selectonchange="intersect()"id="metric"class="wrapper-dropdown"><optionvalue ="190">190</option><optionvalue ="90">90</option><optionvalue ="100">100</option><optionvalue ="300">300</option></select><selectonchange="intersect()"id="metric1"class="wrapper-dropdown"><optionvalue ="100">100</option><optionvalue ="200">200</option><optionvalue ="0">0</option></select>

with

function loadData() {
    alert("loadData reached");
}
function loadData1() {
    alert("loadData1 reached");
}
function intersect() {
    loadData();    
    loadData1();
}

Example: Fiddle

Solution 2:

I not sure why you want to use d3.js and crossfilter.js I do not see a need in your question.

Since you only tag javascript in your question. I am hereby provide you a pure JS solution instead of jquery

var m1 = document.getElementById('metric');

var m2 = document.getElementById('metric1');

m1.onchange = function(){
    //alert(m1.value);//alert(m2.value);var result = intersection(data, data1, m1.value, m2.value);

    if (result != ""){
        for (var i = 0; i < result.length; i++){
            console.log(result[i]);
        }
    }   
}

m2.onchange = function(){

    var result = intersection(data, data1, m1.value, m2.value);

    if (result != ""){
        for (var i = 0; i < result.length; i++){
            console.log(result[i]);
        }
    }
}

//a is the data//b is the data1//v1 is the metric value//v2 is the matric1 valuefunctionintersection(a, b, v1, v2)
{
    var result = [];
    var c = a.concat(b);
    for (var i = 0; i < c.length; i++){

        if (c[i].total == v1 && c[i].tip == v2)
        {                             
            result.push(c[i]);
        }
    }
    return result;
}

JSFiddle try your selection with total = 90 and tip = 0. You will get the so call "intersection" result you want.

Post a Comment for "Cross-filter Using Drop Downs"