新手问题:我最近开始使用 D3 并且一直在玩示例等。在单个 csv 文件上使用 .nest 取得了一些成功,但希望能够做到这一点。SQL 连接的 - 即。使用国家级数据加载一个 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
然后针对每个国家/地区构建“报告”作为子级数据(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 数据 - 或者我没有得到任何东西?