D3.js列数和行数未知

Man*_*nny 2 arrays d3.js

我目前正在创建一个图表(来自外部csv文件的数据)但我事先并不知道列数和行数.您是否可以指出我在哪里可以找到一些有关此问题的帮助(或一些示例)?

谢谢

Tom*_*m P 7

d3.csv可以在这里帮助你:

d3.csv('myCSVFile.csv', function(data){

  //the 'data' argument will be an array of objects, one object for each row so...

  var numberOfRows = data.length, // we can easily get the number of rows (excluding the title row)

      columns = Object.keys( data[0] ),  // then taking the first row object and getting an array of the keys

      numberOfCOlumns = columns.length;  // allows us to get the number of columns

});
Run Code Online (Sandbox Code Playgroud)

请注意,此方法假定电子表格的第一行(仅第一行)是列标题.