javascript - How to find number of data points in a given range in d3 -
i trying find number of data points in series lie in given range (xmin,ymin)
(xmax, ymax)
. give example, if series line plot looks (1,1)
(2,2)
(4,4)
(6,7)
(9,10)
, range (3,3)
(8,8)
, 2 points satisfy criteria looking , => (4,4)
(6,7)
(the actual problem trying solve if have rectangle zoom on series plot, allow zooming if rectangle of zoom @ least captures n data points original series)
is there easy way in d3?
thank you
this straight-forward javascript only:
var data = [[1,1],[2,2],[4,4],[6,7],[9,10]]; function filterdata(minarr, maxarr) { return data.filter(function(d) { return d[0] >= minarr[0] && d[0] <= maxarr[0] && d[1] >= minarr[1] && d[1] <= maxarr[1]; }); } console.log(filterdata([3,3], [8,8])) //[[4,4],[6,7]]
Comments
Post a Comment