user4556738
user4556738

Reputation:

D3.js selecting a part of data to be visualized from a large dataset

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

Answers (2)

crispamares
crispamares

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:

  1. Sort the array with .sort data.sort(function(a, b){return a.Time > b.Time;}))
  2. Create a bisector var bisect = d3.bisector(function(d) { return d.Time; });
  3. We need bisector left and right, so:

    var biLeft = bisec.left, biRight = bisec.right;

  4. 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

user4556738
user4556738

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

Related Questions