I have some code for a line in which I would like to insert filter qualifications. Here’s the code:
const line = d3.line()
.x(function(d,i) {return x(d.payment_amount);})
.y(function(d,i) {return y2(d.cum_pct_total_amt);})
// .curve(d3.curveBasis)
.curve(d3.curveMonotoneX)
;
This code works – however when I try anything like…
const line = d3.line()
.x(function(d,i) {if (i % 100==0) return x(d.payment_amount);})
.y(function(d,i) {if (i % 100==0) return y2(d.cum_pct_total_amt);})
// .curve(d3.curveBasis)
.curve(d3.curveMonotoneX)
;
… the code will fail and the line disappears. The same kind of insertion works elsewhere for me, e.g.
.tickValues(data.map(function(d,i)
{
if ((i % 120 == 0) || (i == xdomain.length-1 )) return d.payment_amount;
}))
What am I missing? What should I do to filter the data at the point of the .x( function call, or is that not allowed?
Thanks for your advice!