score:1

Accepted answer

You can't use a return in this instance. You need to pass a callback function as one of the arguments for filter_data and use that to return the data.

function filter_data(start_time, end_time, callback) {
  var formatDate = d3.time.format("%H:%M"),
  parseDate = formatDate.parse;
  var data1 = [];
  d3.csv("data.txt", function(error, data) {
    data.forEach(function(d) {
      if(parseDate(d.time) >= parseDate(start_time) && parseDate(d.time) < parseDate(end_time)) {
        data1.push(d);
      }
    });
    callback(data1);
  });
}

filter_data(start_time, end_time, function (data) {
  console.log(data);
});

Related Query

More Query from same tag