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?










share|improve this question


















  • 1




    It returns 0 because 0 is less than all years
    – David Lemon
    Nov 8 at 15:34















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?










share|improve this question


















  • 1




    It returns 0 because 0 is less than all years
    – David Lemon
    Nov 8 at 15:34













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 12:16









        fxck

        3,05454383




        3,05454383






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word