Reputation: 4323
I have a d3.js scatterplot based off of this: http://bl.ocks.org/nsonnad/4481531
I'm trying to add in a function that would allow you to filter based on (in the case of the example) country (each represented by a color bubble).
The data comes out of a .csv file, but is rendered as an object like this when I console.log it:
[0 … 99]
0: Object
attribute: "INFJ"
category: "Personality Type"
incidence: "1.04"
index_value: "65"
main_grouping: "Behaviors"
__proto__: Object
1: Object
2: Object
3: Object
ETC...
What I want to do is get all of the rows with a specific main_grouping
. If I do this, I can get a list of all the main_grouping
s, but that's just step one.
d3.csv("example.csv", function(data) {
$.each(data, function (index, value) {
console.log(value.main_grouping);
});
What I don't know how to do with this or from here is to say, given a certain main_grouping
(that will be selected with a dropdown...I can handle this part though), only return those rows as data
for use in the rest of the script that renders the scatterplot.
There's not a server-side option here, so I have to figure out something client-side.
Upvotes: 0
Views: 71
Reputation: 2970
You can use array filter
d3.csv("example.csv", function(data) {
data_filtered = data.filter(function(d){
return d.main_grouping == selected_grouping;
});
}
Upvotes: 1