【问题标题】:Upload csv file using javascript and d3使用 javascript 和 d3 上传 csv 文件
【发布时间】:2014-04-13 04:04:30
【问题描述】:

我是 JavaScript 和 D3 的新手,不知道如何允许用户上传 csv 文件并使用 d3 显示散点图。我正在使用标签来允许用户选择文件。但我不确定下一步应该是什么。有没有办法读取 csv 文件并将其内容存储在 d3 数组中,然后使用该数组显示图形??

提前致谢

【问题讨论】:

    标签: javascript arrays d3.js


    【解决方案1】:

    查看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);
       };
    );
    

    网上有许多示例向您展示如何从数据数组转换为散点图……只需修改这些示例以适合您的特定数据格式。

    【讨论】:

    • 但是用户选择后如何上传文件??
    • 尝试对“上传 csv 文件 javacsript”进行谷歌搜索。
    • 我找了很多,但还是找不到上传文件的方法,所有的例子都是在开发过程中导入文件,而不是从用户端上传文件。我有 并卡在那里:(
    • 但是 csv 文件只包含 2 列,最多 10 行,因此,我只想将文件的内容存储为一个数组,然后 d3 可以使用该数组来绘制一些图表。跨度>
    猜你喜欢
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2019-02-13
    • 2022-07-01
    • 2017-11-13
    相关资源
    最近更新 更多