d3.js: bisector always returns zero
up vote
0
down vote
favorite
http://jsfiddle.net/rdpt5e30/1/
const data = [
{'year': 2005, 'value': 771900},
{'year': 2006, 'value': 771500},
{'year': 2007, 'value': 770500},
{'year': 2008, 'value': 770400},
{'year': 2009, 'value': 771000},
{'year': 2010, 'value': 772400},
{'year': 2011, 'value': 774100},
{'year': 2012, 'value': 776700},
{'year': 2013, 'value': 777100},
{'year': 2014, 'value': 779200},
{'year': 2015, 'value': 782300}
];
const bisect = d3.bisector(function(t: any) { return t.year; }).left;
console.log(bisect(data, 4));
Not matter which position I give it it always returns index 0.. it's literally the same example I've seen countless times, yet it doesn't seems to be working for me for some reason..
Any ideas?
javascript arrays d3.js
add a comment |
up vote
0
down vote
favorite
http://jsfiddle.net/rdpt5e30/1/
const data = [
{'year': 2005, 'value': 771900},
{'year': 2006, 'value': 771500},
{'year': 2007, 'value': 770500},
{'year': 2008, 'value': 770400},
{'year': 2009, 'value': 771000},
{'year': 2010, 'value': 772400},
{'year': 2011, 'value': 774100},
{'year': 2012, 'value': 776700},
{'year': 2013, 'value': 777100},
{'year': 2014, 'value': 779200},
{'year': 2015, 'value': 782300}
];
const bisect = d3.bisector(function(t: any) { return t.year; }).left;
console.log(bisect(data, 4));
Not matter which position I give it it always returns index 0.. it's literally the same example I've seen countless times, yet it doesn't seems to be working for me for some reason..
Any ideas?
javascript arrays d3.js
1
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
http://jsfiddle.net/rdpt5e30/1/
const data = [
{'year': 2005, 'value': 771900},
{'year': 2006, 'value': 771500},
{'year': 2007, 'value': 770500},
{'year': 2008, 'value': 770400},
{'year': 2009, 'value': 771000},
{'year': 2010, 'value': 772400},
{'year': 2011, 'value': 774100},
{'year': 2012, 'value': 776700},
{'year': 2013, 'value': 777100},
{'year': 2014, 'value': 779200},
{'year': 2015, 'value': 782300}
];
const bisect = d3.bisector(function(t: any) { return t.year; }).left;
console.log(bisect(data, 4));
Not matter which position I give it it always returns index 0.. it's literally the same example I've seen countless times, yet it doesn't seems to be working for me for some reason..
Any ideas?
javascript arrays d3.js
http://jsfiddle.net/rdpt5e30/1/
const data = [
{'year': 2005, 'value': 771900},
{'year': 2006, 'value': 771500},
{'year': 2007, 'value': 770500},
{'year': 2008, 'value': 770400},
{'year': 2009, 'value': 771000},
{'year': 2010, 'value': 772400},
{'year': 2011, 'value': 774100},
{'year': 2012, 'value': 776700},
{'year': 2013, 'value': 777100},
{'year': 2014, 'value': 779200},
{'year': 2015, 'value': 782300}
];
const bisect = d3.bisector(function(t: any) { return t.year; }).left;
console.log(bisect(data, 4));
Not matter which position I give it it always returns index 0.. it's literally the same example I've seen countless times, yet it doesn't seems to be working for me for some reason..
Any ideas?
javascript arrays d3.js
javascript arrays d3.js
asked Nov 8 at 12:05
fxck
3,05454383
3,05454383
1
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34
add a comment |
1
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34
1
1
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
So the problem is that we are not supposed to pass it an index, but a value that matches the selector function, so in case of my example 2010 for example.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
So the problem is that we are not supposed to pass it an index, but a value that matches the selector function, so in case of my example 2010 for example.
add a comment |
up vote
0
down vote
So the problem is that we are not supposed to pass it an index, but a value that matches the selector function, so in case of my example 2010 for example.
add a comment |
up vote
0
down vote
up vote
0
down vote
So the problem is that we are not supposed to pass it an index, but a value that matches the selector function, so in case of my example 2010 for example.
So the problem is that we are not supposed to pass it an index, but a value that matches the selector function, so in case of my example 2010 for example.
answered Nov 8 at 12:16
fxck
3,05454383
3,05454383
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53207402%2fd3-js-bisector-always-returns-zero%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It returns 0 because 0 is less than all years
– David Lemon
Nov 8 at 15:34