Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3 Monotone Interpolation - Smoothing a line

Tags:

d3.js

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.

like image 841
paligap Avatar asked Jul 20 '16 04:07

paligap


1 Answers

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.

like image 80
Gerardo Furtado Avatar answered Sep 26 '22 19:09

Gerardo Furtado