Filtering subset of the data

18 views
Skip to first unread message

Venkata Thota

unread,
Nov 16, 2015, 1:37:00 PM11/16/15
to d3-js
Hi,

I am trying to filter certain data based on data. For instance, I have a CSV file that looks similar to the one below. 
I want to filter data based on the VarDate. So lets say I want the data for "2015-05-02". How would I accomplish this? 
I am trying to construct a line chart. 

TimeStep,Pac,Temperature,Vac,VarDate
6:15,0,23.2,208.69,2015-05-01
6:20,0,23.2,208.51,2015-05-01
6:25,0.72,23.2,209.1,2015-05-01
6:20,0,21.21,209.47,2015-05-02
6:25,0,21.22,209.19,2015-05-02
6:30,0,21.26,209.14,2015-05-02
~Thanks
 
 

 

Curran

unread,
Nov 17, 2015, 4:56:16 PM11/17/15
to d3-js
Hello,

Assuming you have a variable "data" with the parsed CSV, and VarDate remains as a string (not parsed into a Date object), the following code will filter the data to contain only the data for "2015-05-02":

data = data.filter(function (d){
  return d.VarDate === "2015-05-02";
});

Best regards,
Curran
Reply all
Reply to author
Forward
0 new messages