Creating a table linked to a csv file

后端 未结 4 1752
暖寄归人
暖寄归人 2020-11-28 02:39

I am trying to create a table linked to a *.csv file using d3, but all I get is a blank webpage. Even with the example Crimea I get a blank page.
I would be

4条回答
  •  旧时难觅i
    2020-11-28 03:21

    Often, I need to refresh a table of data periodically. Here's how I populate a table with data:

    HTML:

    NameAge

    JavaScript:

    function tabulate(data, columns) {
      var table = d3.select("#t1");
      table.select('tbody').remove();  // remove any existing data
      var tbody = table.append('tbody');
      data.forEach(function(row) {
        var tr = tbody.append('tr');
        columns.forEach(function(column) {
          tr.append('td').text(row[column]);
        });
      });
      return table;
    }
    

    Notes:

    • I like to put table headers in the HTML, rather than generate them from JavaScript.
    • I didn't attach the data to the table rows and cells (like @Shawn shows in his answer), because I don't have a need for that. So the code is simpler.

    fiddle

提交回复
热议问题