Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3 interpolated line curve is janky and doubling back on itself

I'm not sure quite how to describe this. The picture basically explains it:cardinal

The faded dots are the points on the curve. You can see the line doubles back on itself and overlaps. I'm just setting it to :

var lineGenerator = d3.svg.line()
    .x(function(d) {
        return xScale(d.date_spaced);
    })
    .y(function(d) {
        return yScale(d.score);
    })
    .interpolate('cardinal');

And each point is only getting plotted once. What am I doing wrong?

And with monotone:

monotone

And linear: enter image description here

like image 258
morgoe Avatar asked Nov 17 '25 14:11

morgoe


1 Answers

Try to increase the tension:

var lineGenerator = d3.svg.line()
    .x(function(d) {
        return xScale(d.date_spaced);
    })
    .y(function(d) {
        return yScale(d.score);
    })
    .interpolate('cardinal').tension(0.95);

Also, try other interpolations (and tension values, but just for "bundle" and "cardinal"), until you find something that fits your purposes.

like image 64
Gerardo Furtado Avatar answered Nov 21 '25 10:11

Gerardo Furtado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!