I'm facing an error in my code when I try to generate time series chart. Anytime I run the code I get this error :

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

I have seen post here which suggests to add this code to the function:

  return collection.filterDate(startDate, endDate)
        reducer2: ee.Reducer.minMax(),
        sharedInputs: true
      .set('system:time_start', startDate.millis());

but it didn't function (I changed the collection into the name of the image collection I have but it didn't work).

here is the code I have :

 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)

  return image.updateMask(mask).divide(10000);

// Map the function over one year of data and take the median.
// Load Sentinel-2 TOA reflectance data.
var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2015-06-23', '2019-07-02')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))

var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],

var clippedCol=dataset.map(function(im){ 
   return im.clip(geometry);

//test if clipping the image collection worked
Map.addLayer(clippedCol.median(), rgbVis, 'RGB');

// Get the number of images.
var count = dataset.size();
print('Count: ',count);
// print(clippedCol);//here I get the error messege "collection query aborted after accumulation over 5000 elements
// print(dataset,'dataset');//the same error here

//function to calculate NDVI
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI');
  return image.addBands(ndvi);


//NDVI to the clipped image collection
var withNDVI = clippedCol.map(addNDVI);

// // Test the addNDVI function on a single image.
// var ndvi1 = withNDVI.select('NDVI').mean();

var colorizedVis = {
  min: 0.0,
  max: 1.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'

// Test the addNDVI function on a single image.

// var ndvi1 = withNDVI.select('first').mean();
// var ndvi2 = withNDVI.select('second').mean();  

print(withNDVI,'NDVI Images');
// Map.addLayer(ndvi1,colorizedVis,'test1');
// Map.addLayer(ndvi2,colorizedVis,'test2');

//Long-Term Time Series
var NDVIalltimes = Chart.image.seriesByRegion(withNDVI,geometry, ee.Reducer.mean(),'NDVI',
30, 'system:time_start').setOptions({
title: 'NDVI for Royal Exchange',
vAxis: {title: 'NDVI'},

The end goal is to get chart that shows the mean NDVI value for each Image in the image collection.

1 Answer 1


The reason for this error is that every image in withNDVI collection does not have system:time_start property. This is normal when you create image with normalizedDifference.

To fix this, simply add copyProperties to the first line in your addNDVI function:

var ndvi = image.normalizedDifference(['B8', 'B4'])
  .copyProperties(image, ['system:time_start'])

And to the last line in your maskS2clouds function:

return image.updateMask(mask).divide(10000)
  .copyProperties(image, ['system:time_start']);

Also, it is recommended to use ui.Chart.image.seriesByRegion instead of Chart.image.seriesByRegion as the later would be removed sooner or later.

  • I have added this line but I still get the same messege
    – ReutKeller
    Commented Jul 3, 2019 at 14:53
  • @Reut It turns out system:time_start disappears as early as after divide method. I've just edited my answer. You should also add copyProperties after divide method.
    – Kevin
    Commented Jul 3, 2019 at 15:20
  • thank you, it worked, but for some reason when it calculates the graph it doesn't use all the images from the imagecollection, and when download as CSV, it put some values twice (for example I have 25.11 twice), do you have any idea why it may occure?
    – ReutKeller
    Commented Jul 3, 2019 at 15:55
  • It is completely normal that several images have the same capture date/time. That's why you see some dates appear twice or more times in CSV file.
    – Kevin
    Commented Jul 3, 2019 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.