Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript D3中的过滤选项_Javascript_Jquery_Graph_D3.js_Rickshaw - Fatal编程技术网

Javascript D3中的过滤选项

Javascript D3中的过滤选项,javascript,jquery,graph,d3.js,rickshaw,Javascript,Jquery,Graph,D3.js,Rickshaw,我正在D3(人力车框架)上工作,在那里我必须使用名称过滤数据 这是人力车用来创建圆圈的代码 var nodes = graph.vis.selectAll("path").data(series.stack.filter(function(d) { return d.y !== null })).enter().append("svg:circle").attr("cx", function(d) { return graph.x(d.x) }).attr("cy", funct

我正在D3(人力车框架)上工作,在那里我必须使用名称过滤数据

这是人力车用来创建圆圈的代码

var nodes = graph.vis.selectAll("path").data(series.stack.filter(function(d) {
    return d.y !== null
})).enter().append("svg:circle").attr("cx", function(d) {
    return graph.x(d.x)
}).attr("cy", function(d) {
    return graph.y(d.y)
}).attr("fill-opacity", 1.0).attr('transform', 'translate(22,0)').attr("r", function(d) {
    return ("r" in d) ? d.r : graph.renderer.dotSize
});
我试图像这样过滤数据

$('#BestBrands input').on("change", function () {   
    console.log("called")
    var selected = $(this).attr('name'),
        display = this.checked ? "inline" : "none";
    console.log(selected)

    graph.vis.selectAll(".filter")
        .data(series.stack.filter(function(d) {
            return series.name[0] == selected
        }))    
        .attr("display", display);
});
//series.name等于d3.js中的d.name,因此series[0]是第一个坐标名称
它不起作用了。我需要在类中附加任何类吗?我对此不清楚。我应该在这里做什么来根据名称过滤数据

如果我理解您的代码:

graph.vis.selectAll("path")
  .data(series.stack.filter(function(d){
        //should return a boolean
        return selected === 'something';
       }))
    .attr("display", display);
});
编辑:

$('#BestBrands input').on("change", function () {   
    console.log("called")
    var selected = $(this).attr('name'),
        display = this.checked ? "inline" : "none";
    console.log(selected)

    graph.vis.selectAll(".filter")
        .data(series.stack.filter(function(d) {
            return series[0].name == selected //assuming series[] is an array
        }))    
        .attr("display", display);
});

如果我理解你的代码:

graph.vis.selectAll("path")
  .data(series.stack.filter(function(d){
        //should return a boolean
        return selected === 'something';
       }))
    .attr("display", display);
});
编辑:

$('#BestBrands input').on("change", function () {   
    console.log("called")
    var selected = $(this).attr('name'),
        display = this.checked ? "inline" : "none";
    console.log(selected)

    graph.vis.selectAll(".filter")
        .data(series.stack.filter(function(d) {
            return series[0].name == selected //assuming series[] is an array
        }))    
        .attr("display", display);
});

看起来您打算使用
var selected=$(this).attr('name')
,但从不将其与任何东西进行比较

在这方面:

series.stack.filter(function(d){ return d.selected })

我怀疑您想将
d.selected
selected
进行比较。现在,这只是我的假设(你知道他们怎么说假设),但是根据我使用D3的经验,
series.stack.filter
将迭代
series.stack
中的元素,因此,您需要确保
d.selected
是您想要的属性。

看起来您打算使用
var selected=$(this).attr('name')
,但决不将其与任何内容进行比较

在这方面:

series.stack.filter(function(d){ return d.selected })
我怀疑您想将
d.selected
selected
进行比较。现在,这只是我的假设(你知道他们怎么说假设),但是根据我使用D3的经验,
series.stack.filter
将迭代
series.stack
中的元素,因此你需要确保
d.selected
是你想要的属性