多维数组切片多个HTML表和导航d3.js
multidimensional array slice multiple html tables and navigation d3.js
我的意图是得到长文件。csv数据到几个html表与500行每个。示例:.csv中的5000行创建10个表,每个表具有不同的内容(即行0-500,500 - 1000,…);还有:10个链接到表
任务:切片数组以获取每个单独表的数据。
基本'伪'代码:
//创建链接
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);
});
我想为每个链接附加一个事件处理程序:
function sliceArray (startslice,stopslice) {
arrofarrays.slice(startslice,stopslice);
};
我不知道如何以编程方式分配变量"startslice,stopslice",以便每个链接都有自己的值。
我的意图是在d3.js中这样做。
我最终选择了以下解决方案:
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);
});
在这里,我使用'+ I '来获得一个变量,该变量在每次调用数据集时增加。我的数据集不包含任何我可以使用的数据。
'start'和'stop'传递给绘制HTML表格的'tabulate'函数中的data.slice(start,stop)。
这给了我想要的效果:每个链接调用数据集的不同切片。
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 单击顶部导航时如何进行向下滚动效果(向下滑动).
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- angular 1.5应用程序中的导航栏
- 无法从jquery Mobile导航栏重定向到另一个页面
- 如何在d3.js中返回路径的y坐标
- d3基于用户选择动态更新节点
- 有条件更新d3.js力图中节点的最佳方法
- 为什么我的d3.jsselectAll+过滤器没有过滤
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 使用D3.js计算带有字母间距的文本长度
- d3中堆栈函数和嵌套函数之间的差异
- 导航到特定事件的另一个变量页面
- MVC 3页面导航和使用javascript传递参数
- 如何在react js中从一个页面导航到另一个页面
- D3.js模式不适用于弧形或圆环图
- d3.js Chord图的动态工具提示
- d3.js:删除/导航到子元素
- 我如何使用d3.js导航JSON嵌套文件
- 多维数组切片多个HTML表和导航d3.js