我正在构建一个仪表板来显示一些数据.我有几个图表和一个列出所有数据的表格.我正在尝试添加搜索功能来过滤图表.我有很多公司和一些关于每个公司的数据.因此,如果我搜索"Appl",只有以"Appl"开头的公司将列在数据表中,图表将反映这一点.
我对当前实现的唯一问题是当我更改此过滤器或清除它时.数据似乎很好,但图表渲染不正确.清除后它们不会返回原始位置,或者以某种方式添加额外数据.任何提示将不胜感激.
$("#table-search").on('input',function(){
text_filter(companyDimension,this.value);//companyDimension is the dimension for the data table
function text_filter(dim,q){
dashTable.filterAll();
var re = new RegExp(q,"i")
if (q!='')
{
dim.filter(function(d){
if (d.search(re)==0)
return d;
});
}
dc.redrawAll();
graphCustomizations(); }});
Run Code Online (Sandbox Code Playgroud)
dc.js代码
var ndx = crossfilter(resource_data);
//Dimensions
companyDimension = ndx.dimension(function(d){
return d["Company Name"]
});
dashTable.width(800).height(800)
.dimension(companyDimension)
.group(function(d){
return "List of all Selected Companies";
})
.size(1774)
.columns([
function(d){return d["Company Name"]; },
function(d){return d["Revenue Source"];},
function(d){return d["Commodity"];},
function(d){return "$"+parseFloat(d["Revenue"]).formatMoney(0,'.',',');}
])
.sortBy(function(d){return d["Company Name"]})
.order(d3.ascending);
Run Code Online (Sandbox Code Playgroud)
就是这样,图表只是在同一个crossfilter对象上过滤不同的维度.
我试着做几件事情给text_filter等功能,dim.filterAll(),dim.filter(null),dc.renderAll() …