D3 Monotone Interpolation - Line Smoothing

I used 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, when I upgrade all my visual studies to version D3 4, I can’t decide how to update the interpolation described above.

I want to smooth the line.

+4
source share
1 answer

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 in which you want to keep monotony.

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

+7
source

Source: https://habr.com/ru/post/1648451/


All Articles