Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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 在函数中传递附加参数时出现问题_Javascript_Json_Function_D3.js - Fatal编程技术网

Javascript 在函数中传递附加参数时出现问题

Javascript 在函数中传递附加参数时出现问题,javascript,json,function,d3.js,Javascript,Json,Function,D3.js,我正试图在d3中编写一个函数,它将检查我的数据的“时间”,看看它是否在其他两个时间之间,并进行相应的过滤 //start with a function to check if time for each data point is in between two other times function timeInterval(data, start, end) { var time = data.Time if (start <= time <= end) {

我正试图在d3中编写一个函数,它将检查我的数据的“时间”,看看它是否在其他两个时间之间,并进行相应的过滤

//start with a function to check if time for each data point is in between two other times
function timeInterval(data, start, end) {
    var time = data.Time

    if (start <= time <= end) {           
        return "inline";
    } else {
        return "none";
    };   
 }

//set the display of points to either inline or none
function updateTime(value) {
d3.selectAll(".events")
    .style("display", timeInterval("20:00", "24:00"));    
}


//When radio button on, call updateTime function
d3.selectAll("#timeFilterRadioButton").on("change", function() {
updateTime()
});

我很想知道我哪里出了问题。谢谢。

只需使用匿名函数获取数据,并将您的
时间间隔
函数包装在其中:

function updateTime(value) {
    d3.selectAll(".events")
        .style("display", function(d) {
            //your datum is here---^
            return timeInterval(d, "20:00", "24:00")
            //use it here-------^
        });
};
不相关,但这:

if (start <= time <= end)

如果(开始我正要写你的最后一句话时,我注意到它有更多的含义!
(“22:00”注意,这在比较数值时有多么不同:
(1@altocumulus),但在数字方面也有一些问题。试试
(1<3<2)
,结果是
true
1<3<2
-->
true<2
-->
1<2
-->
true
。我的目标是向OP展示他们应该做两个比较:
if(foo
。当然。不过,我并不是说数值比较比字符串比较更有效。我第二条评论中的第三个表达式也不正确,至少在数学上不正确。我只是想指出JS中类型强制的特点和微妙之处。虽然表达式在语法上是有效的,但我确信我们可以就
(开始)达成一致
if (start <= time <= end)