D3.js连接来自多个csv文件的数据 [英] D3.js join data from multiple csv files

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

问题描述

我是一个新的D3,并已被任命为创建一个仪表板显示油井数据。数据在3个csv文件中,包含以下标题。

I an new to D3 and have been tasked with creating a dash board for displaying oil well data. The data is in 3 csv files with the following headings.


  1. 公司数据:
    CompanyName,FacilityName,WellName, WellId,WellGasNRI,WellOilNRI,WellShrinkageFactor,WellYieldFactor

  1. Company Data: CompanyName,FacilityName,WellName,WellId,WellGasNRI,WellOilNRI,WellShrinkageFactor,WellYieldFactor

井预算估计:
WellId,Month,Year,MonthInMonth,GrossOil,GrossGas,GrossBOE,NetBOE

Well Budget Estimates: WellId,Month,Year,DaysInMonth,GrossOil,GrossGas,GrossBOE,NetBOE

实际产量:
WellId,Date,GrossOil,GrossGas,NetOil,NetGas,GasWithShrinkage,GasWithYield

Actual well production: WellId,Date,GrossOil,GrossGas,NetOil,NetGas,GasWithShrinkage,GasWithYield

我使用d3.nest对每个文件中的记录进行分组,但是希望将分组的数组合并为单个结构。

I have worked with d3.nest to groups records within each file but would like to merge the grouped arrays into a single structure.

主要显示之一是将每个井的预算估计与实际产量进行比较,然后按设施。

One of the main displays is to compare budget estimate to real production by day for each well then by facility.

任何帮助将非常感谢。

Any help would be greatly appreciated.

推荐答案

一种方法是嵌套多个 d3.csv 调用,如下所述:从D3中的多个csv文件导入数据< a>:

One way to do it is to nest several d3.csv calls, as explained here: Importing data from multiple csv files in D3:

d3.csv("file1.csv", function(data1) {
  d3.csv("file2.csv", function(data2) {
     d3.csv("file3.csv", function(data3) {
        // do something with the data
        console.log("CSV1", data1);
        console.log("CSV2", data2);
        console.log("CSV3", data3);
     });
  });
});

另一种选择(我更喜欢)是使用 d3.queue (这是一个插件 - 您需要分别导入 queue.js

Another option (which I prefer) is to use d3.queue (which is a plugin - you need to import queue.js separately):

queue()
    .defer(d3.csv, 'file1.csv')
    .defer(d3.csv, 'file2.csv')
    .defer(d3.csv, 'file3.csv')
    .await(processData);

function processData(data1, data2, data3) {
    // do something with the data
    console.log("CSV1", data1);
    console.log("CSV2", data2);
    console.log("CSV3", data3);
}



从这里你可以使用d3和JavaScript数组操作函数来组合,拆分和做任何你想要的数据对象。例如,您可能希望使用 d3.nest()。key()来组织CSV,以便可以使用 WellId 字段,然后使用嵌套for循环或某种其他机制组合它们。这里有一些关于D3中数据操作的好的教程和参考:

From there you can use d3 and JavaScript array manipulation functions to combine, merge, split and do anything you want with the data objects. For example, you might want to use d3.nest().key() to organize your CSVs so they can be selected using the WellId field and then combine them using nested for loops or some other mechanism. Here are some good tutorials and references concerning data manipulation in D3:

  • d3-array Documentation
  • Manipulating data like a boss with d3

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

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