paligap
paligap

Reputation: 942

D3 Monotone Interpolation - Smoothing a line

I was using the following code:

var c = d3.line()
.interpolate("monotone")
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); }); 

And now that I am updating all my visual studies to D3 version 4 I can't work out how to upgrade the above interpolation.

I want to smooth the line.

Upvotes: 6

Views: 5474

Answers (1)

Gerardo Furtado
Gerardo Furtado

Reputation: 102188

This is the code using D3 version 4.x:

var c = d3.line()
    .curve(d3.curveMonotoneX)
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.close); }); 

You can also use d3.curveMonotoneY, depending on the axis you want to preserve the monotonicity.

Here is the API.
Link to changes v3 to v4.

Upvotes: 15

Related Questions