Reputation:
I have a large real time incoming data for visualization. I have the speed and time in the dataset. Like if you consider CSV format its like the following
Speed, Time
s1, t1
.......
sn,tn
But I want to visualize say only speed for t1-t10. How can I do that? To the broader sense i should able to select how many time frames i will keep in the chart. May be from t1-t10, t5-t10 or t10-t25 etc.
Have anyone worked with problem like this?
Upvotes: 1
Views: 125
Reputation: 530
While the .filter
method is usually the easiest way of solving a reduction of data for later processing or visualization, in your particular example I would prefer other strategy:
data.sort(function(a, b){return a.Time > b.Time;}))
var bisect = d3.bisector(function(d) { return d.Time; });
We need bisector left
and right
, so:
var biLeft = bisec.left, biRight = bisec.right;
With these functions now we can slice the array and extract the requested information:
var subset = data.slice(biLeft(data, "t5"), biRight(data, "t10"));
Upvotes: 1
Reputation:
I have found a good way to solve the issue. At the beginning I may slice the full data using the following code:
var data=data.slice(startIndex,endIndex);
In this way by changing the starting and ending parameter I can easily change the plots
Upvotes: 0