I have problem with generating charts in GEE. I am trying to calculate NDVI for more than 100 Shapefiles (FeatureCollection) and export the results to a chart and CSV file. I got an error:

Error generating chart: Collection query aborted after accumulating over 5000 elements

How can I revise my code to avoid this error?

// Define a geometry.
var Akdarya = ee.FeatureCollection("users/xodjayevshovkat/Akdarya_GEE_35");

// Make the geometry a feature collection.

// Import S2 image collection.
var S2 = ee.ImageCollection('COPERNICUS/S2')
  // Filter collection.
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20));

// Define a cloud masking function.
var maskcloud1 = function(image) {
  var QA60 = image.select(['QA60']);
  return image.updateMask(QA60.lt(1));

// Define an index function (return only NDVI).
var NDVI = function(image) {
  return image.expression(
    '(NIR - RED) / (NIR + RED)', 
      'NIR': image.select('B8'), 
      'RED': image.select('B4'), 
    }).rename('NDVI').copyProperties(image, image.propertyNames());

// Apply the cloud mask function.
var NDVIcol = S2.map(maskcloud1)
 // Apply the NDVI transformation.

// Calculate the per-pixel median NDRE for all images in collection.
var NDVImed = NDVIcol.median();

// Define vis params.
var NDVIvis = {
  palette: ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a'],
  min: -0.5,
  max: 0.9};

// Plot a time series of 
var plotNDVI = ui.Chart.image.seriesByRegion({
  regions: Akdarya,
  reducer: ee.Reducer.mean(),
  //scale: 1000,
  xProperty: 'system:time_start',
  seriesProperty: 'system:index'})
    title: 'NDVI Akdarya 2018',
    hAxis: {title: 'Date'},
    vAxis: {title: 'NDVI'},

// Display the results.
Map.addLayer(NDVImed.clipToCollection(Akdarya), NDVIvis, 'NDVI');
  • You have to share your 'users/xodjayevshovkat/Akdarya_GEE_35' asset, so this can be tested. Commented Jan 21, 2020 at 19:48
  • Perhaps you could try to use weekly or monthly aggregates when you're charting. Commented Jan 21, 2020 at 19:55
  • 1
    The asset is still not shared. To share an asset, you click on the asset in the left-hand-side "Assets" tab, click "Share", check the "Anyone can read" box, finally click "Done". Commented Jan 22, 2020 at 6:44
  • 1
    'users/xodjayevshovkat/Akdarya_GEE_35' is still not accessible by me Commented Jan 22, 2020 at 9:40

1 Answer 1


Your image collection contains 493 images, and your feature collection contains 35 features. Combining these, you end up with over 17,000 elements. There’s a limit of 5,000. This means, you cannot chart more than 10 regions at a time (4,930 elements).

You could create multiple charts, each with no more than 10 regions in each. Perhaps even have a separate chart for each region?

var regions = Akdarya.toList(Akdarya.size())
var regionCount = Akdarya.size().evaluate(function (count) {
  for (var i = 0; i < count; i++) {
    var plotNDVI = ui.Chart.image.seriesByRegion({
      regions: ee.FeatureCollection([ee.Feature(regions.get(i))]),
      reducer: ee.Reducer.mean(),
      xProperty: 'system:time_start',
      seriesProperty: 'Farmers'})
        title: 'NDVI Akdarya 2018',
        hAxis: {title: 'Date'},
        vAxis: {title: 'NDVI'},



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.