Sorting 更新时对表行进行排序和筛选
我正试图根据一年中不断变化的数据更新一个表。问题是,我只想显示数据10项的一个子集,而这与排序函数不配合。当我删除过滤器功能时,按值动态排序工作正常,但所有数据都显示出来。使用筛选功能,排序功能不起作用,按字母顺序显示前10项。有没有关于如何正确集成过滤器功能的建议?我是否需要通过更新、退出、删除再次绑定数据 这是我的密码:Sorting 更新时对表行进行排序和筛选,sorting,d3.js,filtering,Sorting,D3.js,Filtering,我正试图根据一年中不断变化的数据更新一个表。问题是,我只想显示数据10项的一个子集,而这与排序函数不配合。当我删除过滤器功能时,按值动态排序工作正常,但所有数据都显示出来。使用筛选功能,排序功能不起作用,按字母顺序显示前10项。有没有关于如何正确集成过滤器功能的建议?我是否需要通过更新、退出、删除再次绑定数据 这是我的密码: var rows_cotton = tbody_cotton.selectAll("tr") .data(all) .sort(function(a
var rows_cotton = tbody_cotton.selectAll("tr")
.data(all)
.sort(function(a, b){ return d3.descending(parseInt(data_cotton_pc()[a.id]), parseInt(data_cotton_pc()[b.id])); })
.enter()
.append("tr")
.filter(function(d,i) { return i < 10 })
var cells_cotton_name = rows_cotton
.append("td")
.attr("class","column_name")
.text(function(d,i){return nameById[d.id];})
var cells_cotton_bar = rows_cotton
.append("td")
.attr("class","column_bar")
.append("svg")
.attr("width", 180)
.attr("height", 5)
.append("rect")
.attr("height", 5)
.attr("width", function(d) { return table_bars(parseFloat(data_cotton_pc()[d.id])); })
.attr("fill","#BA3459")
var cells_cotton_number = rows_cotton
.append("td")
.attr("class","column_number")
.text(function(d,i){return data_cotton_pc()[d.id];})
在将数据传递给D3之前,我会对数据进行排序和过滤,而不是选择。我试过了。但是我仍然有更新函数的问题。在其他年份,前十名中有不同的项目。当我过滤之前的数据时,总是有相同的10个项目只是改变位置和值,因为其他项目在开始时被过滤掉了。
rows_cotton
.sort(function(a, b){ return d3.descending(parseInt(data_cotton_pc()[a.id]), parseInt(data_cotton_pc()[b.id])); });
cells_cotton_name
.text(function(d,i){return nameById[d.id];})
cells_cotton_bar
.attr("width", function(d) { return table_bars(parseFloat(data_cotton_pc()[d.id])); })
cells_cotton_number
.text(function(d,i){return data_cotton_pc()[d.id];});