Google Earth Engine – How to Specify System:time_start in Time Series Charts

google-earth-enginejavascript

I want to plot mean NDVI throughout the period of interest.

I have a polygon file loaded in Asset called boundary.

var start = ee.Date('2017-05-01'); //Dates of interest
var finish = ee.Date('2018-10-31'); 
var sentinel = ee.ImageCollection('COPERNICUS/S2')
 .filterBounds(boundary)
 .filterDate(start, finish)
 .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 5)); 

var NDVI = sentinel.map(
    function(img) {
         return img.normalizedDifference(['B8','B4'])
                  .rename('NDVI');
    });

print(NDVI);
print(ui.Chart.image.series(NDVI, boundary, ee.Reducer.mean(), 10));

But it turns out Error generating chart: No features contain non-null values of "system:time_start". How do I specify "system:time_start" argument?

Best Answer

Use copyProperties method:

var NDVI = sentinel.map(
    function(img) {
         return img.normalizedDifference(['B8','B4'])
                  .rename('NDVI')
                  .copyProperties(img, ['system:time_start']);
    });