I am new in google earth engine, i am trying to plot the time series NDVI value and images as well, i found a script and i tried to modified but its not working properly. Below is the code

its giving error that, Error generating chart: The image collection is empty.

I just changed here the var geometry, and i imported the KML file using fusion table and paste the link here. How to display the statistics graph and images also for selected region

//Import GEE Feature Collection (My AOI kml)
    var geometry = ee.FeatureCollection('ft:19HmlYA6D2W-soGuCJGOvdEutyTNdZFK1tUFz2JAM');

// Create image collection of S-2 imagery for the perdiod 2016-2019
var S2 = ee.ImageCollection('COPERNICUS/S2')

//filter start and end date
.filterDate('2016-02-01', '2019-02-28')

//filter according to drawn boundary

// Function to mask cloud from built-in quality band
// information on cloud
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
return image.updateMask(QA60.lt(1));

// Function to calculate and add an NDVI band
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']));

// Add NDVI band to image collection
var S2 = S2.map(addNDVI);
// Extract NDVI band and create NDVI median composite image
var NDVI = S2.select(['nd']);
var NDVImed = NDVI.median(); //I just changed the name of this variable ;)

// Create palettes for display of NDVI
var ndvi_pal = ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b',

// Create a time series chart.
var plotNDVI = ui.Chart.image.seriesByRegion(S2, geometry,ee.Reducer.mean(),
'nd',500,'system:time_start', 'system:index')
                title: 'NDVI short-term time series',
                hAxis: {title: 'Date'},
                vAxis: {title: 'NDVI'}

// Display.

// Display NDVI results on map
Map.addLayer(NDVImed.clip(geometry), {min:-0.5, max:0.9, palette: ndvi_pal}, 'NDVI');

1 Answer 1


The geometry of your asset is inside the property 'geometry'. you have to tell the Earth Engine to get the geometry from that property using the argument 'column'.

//Import GEE Feature Collection (My AOI kml)
var geometry = ee.FeatureCollection('ft:19HmlYA6D2W-soGuCJGOvdEutyTNdZFK1tUFz2JAM', 'geometry');

However, reducing over such a large region will probably run into memory issues. So consider using smaller regions of interest or a larger scale. Eventually export the results.

Then it should work: link code

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.