新手问题:我最近开始使用D3并且一直在玩示例等。在一个单独的csv文件上使用.nest取得了一些成功但希望能够做到当量。一个SQL Join - 即。使用国家/地区级别数据加载一个csv文件,然后在第二个文件中嵌套子项数据。
父级国家/地区数据(csv文件摘录) - 以及任何其他国家/地区级数据......
Country,ID,Status,...[other Country fields]...
Afghanistan,AF,CAND
Albania,AL,CAND
Australia,AU,OTHER
Azerbaijan,AZ,COMP
Burkina Faso,BF,CAND
Cameroon,CM,CAND
Central African Republic,CF,COMP
Côte d'Ivoire,CI,CAND
Democratic Republic of Congo,CZ,CAND
然后在“Reports”中构建针对每个国家/地区的子级别数据(csv文件摘录)
Country,CountryReport,YearsCovered,SectorsCovered,...[other Report fields]...
Afghanistan,http://eiti.org/report/afghanistan/2008,2008,"Mining"
Afghanistan,http://eiti.org/report/afghanistan/2009,2009,"Mining"
Albania,http://eiti.org/report/albania/2009,2009,"Oil, Mining"
Azerbaijan,http://eiti.org/report/azerbaijan/2007,2007,"Oil, Gas"
Azerbaijan,http://eiti.org/report/azerbaijan/2008,2008,"Oil, Gas"
Azerbaijan,http://eiti.org/report/azerbaijan/2009,2009,"Oil, Gas, Mining"
Azerbaijan,http://eiti.org/report/azerbaijan/2010,2010,"Oil, Gas, Mining"
Azerbaijan,http://eiti.org/report/azerbaijan/2011,2011,"Oil, Gas, Mining"
Burkina Faso,http://eiti.org/report/burkina-faso/2008,2008,"Mining"
Burkina Faso,http://eiti.org/report/burkina-faso/2009,2009,"Mining"
Burkina Faso,http://eiti.org/report/burkina-faso/2010,2010,"Mining"
Cameroon,http://eiti.org/report/cameroon/2004,2004,"Oil, Gas"
Cameroon,http://eiti.org/report/cameroon/2005,2005,"Oil, Gas"
Cameroon,http://eiti.org/report/cameroon/2006,2006,"Oil, Gas, Mining"
Cameroon,http://eiti.org/report/cameroon/2007,2007,"Oil, Gas, Mining"
Cameroon,http://eiti.org/report/cameroon/2008,2008,"Oil, Gas, Mining"
任何想法如何最好地解决这个问题?我尝试过使用.nest,但我认为这意味着父级数据需要包含在子文件的每一行中?
如果我可以将csv数据加载到全局变量中,我可以构建这个结构 - 但是d3js似乎不允许这样做。对此的解释也将受到赞赏
https://github.com/mbostock/d3/wiki/Requests
的示例代码var data; // a global
d3.json("path/to/file.json", function(json) {
data = json;
visualizeit();
});
...似乎不适用于csv数据 - 或者我可能没有得到什么?