Well d.x would be the current x value and[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;

.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 =;
    if(d.y < 0.7){"fill", "green");
    lastx = d.x; // make this the previous value for the next element
    return prozent(d.y); });

Related Query