My data is all in one long form CSV file and I want the user to be able to choose which country's data they would like to have visualized. In order to do that, I am using the filter function in D3.js. When they choose a country as input, the program will filter out all rows that do not match the input in the CountryName column. Then, it would visualized the filtered data.
I was hoping something like this would work.
data = data.filter(function(d) { return d.CountryName === "China"});
Yet when I do this, I get "data.filter is not a function." I have seen d3.js code that successfully uses data.filter... why won't it work here?
Additional Info:
One of the comments asked what data is. Here's what I have for data:
data = d3.csv("econDataLong.csv", function(d) {
return {
CountryName: d.CountryName,
IndicatorName: d.IndicatorName,
Year: d.Year,
Value: +d.Value
} }
);
filtered = data.filter(function(d) { return d.CountryName === "China"});
console.log(filtered);
I have been doing this to see if I can get filter working, but so far no luck.