从 D3 中的多个 csv 文件导入数据 [英] Importing data from multiple csv files in D3

查看:32
本文介绍了从 D3 中的多个 csv 文件导入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 D3 的新手,刚刚开始从事一个项目.我的问题是这个.我想从 D3 中的 2 个 csv 文件导入数据以将它们用于图形比较.我面临的问题是:

1.如何从多个csv文件中导入数据.
2.我可以为每个csv使用一个数组还是D3只使用一个全局数据数组?
3.有没有办法从csv文件中选择某一列导入?

这是一个示例,我想从单独数组中的每个文件中导入oldVer",然后使用这 2 个数组进行处理.这在 D3 中可行吗?如何实现?

I am brand new to D3 and just started working on an a project. My question is this. I want to import data from 2 csv files in D3 to use them for graph comparisons. The problems I am facing are:

1.How do I import data from multiple csv files.
2.Can I use one array for each csv or does D3 use only one global data array?
3.Is there a way to choose a certain column from the csv files to import?

Here is an example, I want to import the "oldVer" from each of the files in separate arrays and then use the 2 arrays to work with. Is that posible in D3 and how?

csv 1
时间,旧版本,新版本,旧T,新T
1,180930,190394,24,59
2,198039,159094,26,45
3,152581,194032,22,61

csv 1
time,oldVer,newVer,oldT,newT
1,180930,190394,24,59
2,198039,159094,26,45
3,152581,194032,22,61

csv 2
时间,旧版本,新版本,旧T,新T
1,184950,180435,27,26
2,120590,129409,13,13
3,165222,182133,60,54

csv 2
time,oldVer,newVer,oldT,newT
1,184950,180435,27,26
2,120590,129409,13,13
3,165222,182133,60,54

再次为这个愚蠢的问题感到抱歉,但我对此事的反馈很少.任何帮助将不胜感激.

Again sorry for the dumb question but I have found little feedback on this matter. Any help will be appreciated.

推荐答案

在 d3 版本 5 中,您可以使用 Promise.all 加载多个 csv 文件.示例:

In d3 version 5, you can use Promise.all to load multiple csv files. Example:

Promise.all([
    d3.csv("file1.csv"),
    d3.csv("file2.csv"),
]).then(function(files) {
    // files[0] will contain file1.csv
    // files[1] will contain file2.csv
}).catch(function(err) {
    // handle error here
})

有关在 d3 v5 中加载 csv 的更多信息

有关 Promise 的更多信息.all()

这篇关于从 D3 中的多个 csv 文件导入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆