Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3.js filter from csv file using multiple columns

Tags:

csv

d3.js

I want to filter using multiple column values from csv. I first want to filter by city and then criticality columns. I would like to filter Criticality (high/medium/low).

How to filter using AND/OR ?

City and Criticality are checkboxes and based on the selections i want to filter the data from the respective csv columns. looking at efficient way of filter.

Can i have something like

(d["Criticality]=="High" || d["Criticality"]=="Low")

currently this is what i am doing:

var City="London";
 var strSevText="High";

    d3.csv("Status.csv", function(consdata) {

    var filtercitydata = consdata.filter(function(d, i) 
    { 

            if (d["City"] == City) 
            { 
                return d; 
            } 

        })

    var filtersevdata = filtercitydata.filter(function(d, i) 
        { 
            if (d["Criticality"] == strSevText) 
            { 
                return d; 
            } 

        })

      })

My CSV file data :

Application_Id,Application Name,Status,Name,City,Criticality
200009,OARINK,RED,Jen,London,High
200039,3000 DEALING,RED,Marc,London,High
200044,KON,RED,Martin,London,High
200067,D3 MATCHING,RED,Marc,London,Medium
200070,Next Generation,RED,Marc,London,High
200088,ONE,RED,Jonathan,London,High
200097,R-CHECK,RED,Graham,Paris,High
200097,D-CHECK-I,RED,Graham,Mumbai,Low
200107,CON,RED,Cary Fel,Paris,High
like image 364
krishna_v Avatar asked Apr 18 '14 15:04

krishna_v


1 Answers

You can write exactly what you have as a suggestion in your question:

var filteredData = consdata.filter(function(d) 
{ 

        if( d["City"] == "City") || (d["Criticality"]=="High" || d["Criticality"]=="Low")
        { 
            return d;
        } 

    })
like image 142
Lars Kotthoff Avatar answered Nov 17 '22 17:11

Lars Kotthoff