score:1

Well d.x would be the current x value and node.data()[i-1].x would be the previous x value, where i > 0.

The alternative is you could just use a var like so:

var lastx = undefined;

node.append("text")
.attr("x", function(d) { return x(d.x); })
.attr("y", function(d) { return y(d.y); })
.text(function(d,i) {

    console.log(d.x, lastx); // do whatever you want to do comparing d.x and lastx

    var header = d3.select(this);
    if(d.y < 0.7){
        header.style("fill", "green");
    }
    lastx = d.x; // make this the previous value for the next element
    return prozent(d.y); });

Related Query