我是 JavaScript 和 D3 新手,无法弄清楚如何允许用户上传 csv 文件并使用 d3 显示散点图。我正在使用标签来允许用户选择文件。但我不确定下一步应该做什么。有没有办法读取 csv 文件并将其内容存储在 d3 数组中,然后使用该数组显示图形?
提前致谢
最佳答案
查看 d3.csv
函数 ( https://github.com/mbostock/d3/wiki/CSV )。这是一个简单的例子
//load up the example.csv file
d3.csv('example.csv',
function(data){
//this is an object, the contents of which should
//match your example.csv input file.
console.log(data);
// do more stuff with 'data' related to
// drawing the scatterplots.
//
//-----------------------
},
function(error, rows) {
console.log(rows);
};
);
网上有许多示例向您展示如何从数据数组转换为散点图...只需修改这些示例以适合您的特定数据格式即可。
关于javascript - 使用 javascript 和 d3 上传 csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22293620/