简体   繁体   English

多维数组切片多个html表和导航d3.js

[英]multidimensional array slice multiple html tables and navigation d3.js

My intent is to a get long file.csv data into several html tables with 500 rows each. 我的意图是将较长的file.csv数据放入几个html表中,每个表具有500行。 Example: 5000 rows in the .csv create 10 tables, each with different content ( that is row 0-500, 500 - 1000, ...); 示例:.csv中的5000行创建10个表,每个表具有不同的内容(即行0-500、500-1000,...); also: 10 links to reach the tables. 还:到达表的10个链接。

Task: slice the array to get the data(data) for each individual table. 任务:切片数组以获取每个单独表的数据。

Basic 'pseudo'-code so far: 到目前为止,基本的“伪”代码:

// creating links //创建链接

var rowli = boxlist.selectAll("li")
                .data(groups)
                .enter()
                .append("li")
                .append("div")
                .text(function(d) {return d.length;})
                .on("click",Slide);
                .on("mousedown",tabulate(startslice=0,stopslice=500);

//function that draws table:

function tabulate(data, groups,startslice, stopslice) {

var boxlist = d3.select("#ul_id")
                .append("ul")

// create links with popout transition, target is view-select.


//create table

var table = d3.select("#container").append("table"),
    tbody = table.append("tbody");

// create a row for each object in the data

var rows = tbody.selectAll("tr")
    .data(data.slice(startslice,stopslice)
    .enter()
    .append("tr")

// each row appends td

  rows.append("td")
    .html(function(d) { return d[0];});
return table;
};

// render the table

var peopleTable = d3.text("data.csv", function(data) {

var arrofarrays = d3.csv.parseRows(data);

var groupsize = 500;
var groups = arrofarrays.map(function(item, index){
  return index % groupsize === 0 ? arrofarrays.slice(index, index+groupsize) : null;})
.filter(function(item) {return item;});

var peopleTable = tabulate(arrofarrays, groups);

}); 

I want to attach an event handler to each link: 我想将事件处理程序附加到每个链接:

function sliceArray (startslice,stopslice) {
 arrofarrays.slice(startslice,stopslice);
};

I cannot figure out how to assign the variables "startslice,stopslice" programmatically so that each link will have its own values. 我无法弄清楚如何以编程方式分配变量“ startslice,stopslice”,以便每个链接都有自己的值。

My intent is to do this in d3.js. 我的目的是在d3.js中执行此操作。

I finally chose the following solution: 我终于选择了以下解决方案:

var rowli = boxlist.selectAll("li")
                .data(groups)
                .enter()
                .append("li")
                .append("div")
                .attr("class","innerLi")
                .attr("data-vin","view-select")
                .attr("data-sd","popout")
                .attr("id",function(d, i){var result='a'+i; return result; })
                .text(function(d) {return d.length;})
                .on("click",Slide);

     boxlist.selectAll("div").on("mousedown",function(d,i) { 
        tabulate (arrofArro, groups, start=+i*groupsize, stop=(+i+1)*groupsize); 
    });

Here, I use '+i' to get a variable that increases each time that the dataset is called. 在这里,我使用“ + i”来获取一个变量,该变量在每次调用数据集时都会增加。 My dataset does not contain any data that I could have used. 我的数据集不包含我可以使用的任何数据。

'start' and 'stop' are passed to data.slice(start,stop) inside the 'tabulate' function that draws the html table. “开始”和“停止”传递到绘制html表的“制表”函数内部的data.slice(start,stop)。

This gives me the desired effect: each link calls a different slice of the dataset. 这给了我想要的效果:每个链接调用数据集的不同部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM