score:7

Accepted answer

Use .classed('yourclass', true), see docs:

allDots1.on('click', function(d, i) { //i==index, d==obj of clicked point
    console.log(JSON.stringify(myCSV[i]));
    var arrWeeks = [i];

    for (var xx = 0; xx < myCSV.length; xx++) {
        var t1 = myCSV[xx].car - d.y;
        var t2 = d.y - myCSV[xx].car;
        var looptest = (t1 < 30 && t1 > 0) || (t2 < 30 && t2 > 0);
        console.log(myCSV[xx].car + ' (loop val) is/not within 30 of ' + d.y + '(clicked val)' + looptest);
        if ((t1 < 30 && t1 > 0) || (t2 < 30 && t2 > 0)) {
            arrWeeks.push(xx); //All index points in "Cars" that are within 30 of clicked point
        }
    } //ENDFOR
    console.log("%s %o", 'arrWeeks: ', arrWeeks);
    allDots1.classed('reddot', false);
    allDots1.classed('greendot', false);
    allDots2.classed('greendot', false);
    allDots3.classed('greendot', false);
    arrWeeks.forEach((i) => {
        allDots1.filter((d, j) => j === i).classed('greendot', true);
        allDots2.filter((d, j) => j === i).classed('greendot', true);
        allDots3.filter((d, j) => j === i).classed('greendot', true);
    });
    allDots1.filter((d, j) => j === i).classed('reddot', true);
});

Working demo


Related Query