我想在使用 javascript(使用 d3 库)加载之前从 CSV 文件中选择一些数据。
这就是我加载 CSV 的方式:
d3.csv("data.csv", function(csv) {
vis.datum(csv).call(chart);
});
这是 CSV 文件的示例:
Class,Age,Sex,Survived
First Class,Adult,Male,Survived
First Class,Adult,Male,Survived
First Class,Adult,Male,Survived
First Class,Adult,Male,Survived
First Class,Adult,Male,Survived
First Class,Adult,Female,Survived
First Class,Adult,Female,Survived
First Class,Adult,Female,Survived
Second Class,Adult,Male,Perished
Second Class,Adult,Male,Perished
Second Class,Adult,Male,Perished
Third Class,Adult,Male,Survived
Third Class,Adult,Male,Survived
Third Class,Adult,Male,Survived
Third Class,Adult,Male,Survived
Third Class,Adult,Male,Perished
Third Class,Adult,Male,Perished
Crew,Adult,Male,Perished
Crew,Adult,Male,Perished
Crew,Adult,Female,Survived
Crew,Adult,Female,Survived
例如,我只想在加载它之前选择Second Class
和First Class
行d3.csv
。
我知道我可以删除 CSV 中的其他行,但我想创建一个函数,以便用户可以选择他想要使用的类别。我希望这有点道理。