简体   繁体   English

使用javascript和d3上传CSV文件

[英]Upload csv file using javascript and d3

I am new to JavaScript and D3 and cannot figure out how to allow users to upload a csv file and displaying a scatterplot using d3. 我是JavaScript和D3的新手,无法弄清楚如何允许用户上传CSV文件和使用d3显示散点图。 I am using the tag to allow user to select file. 我正在使用标签允许用户选择文件。 But I am not sure on what the next step should be. 但是我不确定下一步应该怎么做。 Is there a way to read the csv file and store it's contents in a d3 array and then displaying a graph using that array ?? 有没有办法读取csv文件并将其内容存储在d3数组中,然后使用该数组显示图形?

Thanks in advance 提前致谢

Look into the d3.csv function ( https://github.com/mbostock/d3/wiki/CSV ). 查看d3.csv函数( https://github.com/mbostock/d3/wiki/CSV )。 Here is a simple example 这是一个简单的例子

//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);
   };
);

There are a number of examples online showing you how to go from a data array to a scatterplot...it's a matter of modifying those examples to fit your specific data format. 在线上有许多示例向您展示了如何从数据阵列转到散点图...需要修改这些示例以适合您的特定数据格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM