Google Earth Engine Chart – Fix ‘No Features Contain Non-Null Values of system:time_start’ Error

chart;errorgoogle-earth-engine

I'm trying to plot a chart from a collection I have created. While the data from this collection maps fine, I can't seem to produce a chart for it.

var sstMonthly = temporalCollection(sst, ee.Date('2013-01-01'), 12, 1, 'month');
print('sstMonthly', sstMonthly)

print(ui.Chart.image.series(sstMonthly, BIOT, ee.Reducer.mean(), 500));

Which gives this error;

Error generating chart: No features contain non-null values of "system:time_start".

From what I've read it seems that the error is probably because it can't find the property. But nowhere states how to find that property in the image collection or what the correct syntax to add it into the code for charts is. Any help?

Best Answer

exports.temporalCollection = function(collection, start, count, interval, units) {
  // Create a sequence of numbers, one for each time interval.
  var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));

  var originalStartDate = ee.Date(start);

  return ee.ImageCollection(sequence.map(function(i) {
    // Get the start date of the current sequence.
    var startDate = originalStartDate.advance(ee.Number(interval).multiply(i), units);

    // Get the end date of the current sequence.
    var endDate = originalStartDate.advance(
      ee.Number(interval).multiply(ee.Number(i).add(1)), units);

    return collection
        .filterDate(startDate, endDate)
        .mosaic()
        .set('system:time_start', startDate.millis());
  }));
}
Related Question